NutzCN Logo
问答 使用1.65的包后,module的json视图会把字符串"0"变成true
发布于 2469天前 作者 忧郁深蓝 2077 次浏览 复制 上一个帖子 下一个帖子
标签:

pom.xml

<modelVersion>4.0.0</modelVersion>
	<groupId>nutz_novel</groupId>
	<artifactId>nutz_novel</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>nutz_novel</name>
	<description />
	<properties>
		<webVersion>3.1</webVersion>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<nutz-version>1.r.65-SNAPSHOT</nutz-version>
	</properties>
	<!-- 指定一个maven资源地址 -->
	<repositories>
		<repository>
			<id>ossrh</id>
			<url>https://jfrog.nutz.cn/artifactory/snapshots</url>
			<snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			</snapshots>
			<releases>
				<enabled>false</enabled>
			</releases>
		</repository>
		<repository>
			<id>rivetlogic</id>
			<name>rivetlogic</name>
			<url>http://maven.rivetlogic.com/nexus/content/repositories/public</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<releases>
				<enabled>false</enabled>
			</releases>
		</repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>javax.servlet.jsp.jstl</artifactId>
			<version>1.2.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<!-- NUTZ框架 -->
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutz</artifactId>
			<version>${nutz-version}</version>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutz-integration-quartz</artifactId>
			<version>${nutz-version}</version>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutz-plugins-mock</artifactId>
			<version>${nutz-version}</version>
			<scope>test</scope>
		</dependency>
		<!-- 定时任务框架 -->
		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
			<version>2.2.3</version>
		</dependency>
		<!-- 日志框架 -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<!-- 数据库连接 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.26</version>
			<exclusions>
				<exclusion>
					<groupId>com.alibaba</groupId>
					<artifactId>jconsole</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.alibaba</groupId>
					<artifactId>tools</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.41</version>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.44</version>
		</dependency>
		<!-- APACHE框架 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.4</version>
		</dependency>
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils-core</artifactId>
			<version>1.8.3</version>
		</dependency>
		<dependency>
			<groupId>commons-collections</groupId>
			<artifactId>commons-collections</artifactId>
			<version>3.2.1</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.10</version>
		</dependency>
		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.6</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1</version>
			<exclusions>
				<exclusion>
					<groupId>logkit</groupId>
					<artifactId>logkit</artifactId>
				</exclusion>
				<exclusion>
					<groupId>avalon-framework</groupId>
					<artifactId>avalon-framework</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<!-- JUNIT测试框架 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<!-- 此框架用来支持junit多线程,可以测试并发--> 
		<dependency> 
			<groupId>net.sourceforge</groupId> 
			<artifactId>GroboUtils</artifactId> 
			<version>5-core</version> 
		</dependency> 

		<!-- 前台模版框架 -->
		<dependency>
			<groupId>com.github.subchen</groupId>
			<artifactId>jetbrick-template-nutz</artifactId>
			<version>2.1.2</version>
		</dependency>
		<!-- JSON WEB TOKEN 框架 -->
		<dependency>
			<groupId>com.nimbusds</groupId>
			<artifactId>nimbus-jose-jwt</artifactId>
			<version>4.28</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>3.2.5</version>
		</dependency>

         <!--  验证码  -->
		<dependency>
			<groupId>cn.apiclub.tool</groupId>
			<artifactId>simplecaptcha</artifactId>
			<version>1.2.2</version>
		</dependency>


	</dependencies>

这个是module

@At("/toLogin")
	@Ok("json")
	public Object toLogin(String user_name,String password,String code){
		try{
			CodeUtils.checkCode(code);
			rightBS.login(user_name, password);
		}catch(Exception e){
			return ExceptionBulider.handelException(e);
		}
		return new Msg();
	}

msg内的属性是 code="0" msg="操作成功"

页面接收到返回后,会把"0"变成true

原先用的是1.61 值是不会变的,换了1.65后,就发生改变了,有没有大神知道为什么

10 回复

我修改版本为1.61后,返回值又变成0了;

public class Msg {

private String code;
private String msg;
private Object data;

public static String successCode="0";

public Msg(){
    this.code = successCode;
    this.msg = "操作成功";
}

public Msg(String code,String msg){
    this.code = code;
    this.msg = msg;
}

public Msg(String code,String msg, Object data){
    this.code=code;
    this.msg=msg;
    this.data=data;
}
public static Msg successMsg(String msg){
    return new Msg(successCode,msg,null);
}
public static Msg success(String content, Object data) {
    return new Msg(successCode, content, data);
}
public static Msg error(String code, String content) {
    return new Msg(code, content, null);
}

public static Msg error(String content) {
    return new Msg("1", content, null);
}

public boolean isCode(){
    return code==successCode;
}
public String getCode() {
    return code;
}
public void setCode(String code) {
    this.code = code;
}
public String getMsg() {
    return msg;
}
public void setMsg(String msg) {
    this.msg = msg;
}
public Object getData() {
    return data;
}
public void setData(Object data) {
    this.data = data;
}

public String toString(){
    return "code="+this.code+" | msg="+this.msg+" | data="+this.data;
}

}

页面代码也贴一下

$(function() {
var base = $("#base").val();
next_captcha();//这里是更换验证码
$("#login_button").click(function() {
$("#login_button").hide();
$.ajax({
url : base + "/code/toLogin",
type: "POST",
data:$('#loginForm').serialize(),
error: function(request) {
alert("Connection error");
},
dataType:"json",
success: function(data) {
if (data.code=="0") {
// alert(data.msg);
location.href=base+"/yt/abc/";
} else {
alert(data.msg);
next_captcha();
$("#login_button").show();
}

        }
    });
    return false;
});

});

console.log(data) 输出什么,贴一下

Object { code: "0", msg: "操作成功" }
额 我又改回1.65的 现在又正常了...搞不懂为什么了

......................

蛋蛋最帅(ฅ>ω<*ฅ)

添加回复
请先登陆
回到顶部