查询用户是否存在
user.setPassword(passwd);
if (create) {
int count = userService.count(Cnd.where("user_name", "=", user.getUser_name()));
if (count != 0) {
return "用户名已经存在";
}
} else {
if (user.getUser_id() < 1) {
return "用户Id非法";
}
}
异常信息
DEBUG org.nutz.service.EntityService - Get TypeParams for self : nuoshang.bluejay.bean.User
2016-08-17 10:32:43,660 [qtp22805895-23] WARN org.nutz.mvc.impl.processor.FailProcessor - Error@/user/save :
java.lang.NullPointerException
at org.nutz.service.EntityService.count(EntityService.java:165)
at nuoshang.bluejay.modules.UserModule.checkUser(UserModule.java:150)
at nuoshang.bluejay.modules.UserModule.save(UserModule.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
user 类
@Id
@Column("user_id")
private int user_id;
/****用户名 ****/
@Name
@Column("user_name")
private String user_name;
/****用户密码 ****/
@Column("password")
@ColDefine(width = 128)
private String password;
调用的方法
/**
* 根据条件统计符合条件的记录数
*
* @param cnd
* 查询条件
* @return 记录数
*/
public int count(Condition cnd) {
return dao().count(getEntityClass(), cnd);
}