大家好:
我使用Nutz来建立实体类和数据表之间的映射关系,下面会贴上代码,我遇到的问题是,我使用查询之后,总是得不到createdTime和updatedTime的值,因为这两个属性和set/get方法都放在父类basePOJO中,我该如何才能获取得到呢?
- User类
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.ManyMany;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.Table;
@Table("t_user")
public class User extends BasePojo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
protected int id;
@Name
@Column
protected String name;
@Column("passwd")
@ColDefine(width=128)
protected String password;
@Column
protected String salt;
@Column
protected String email;
@Column
protected String department;
@Column
protected String position;
@Column
protected boolean locked;
@ManyMany(from="u_id", relation="t_user_role", target=Role.class, to="role_id")
protected List<Role> roles;
@ManyMany(from="u_id", relation="t_user_permission", target=Permission.class, to="permission_id")
protected List<Permission> permissions;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public List<Role> getRoles() {
return roles;
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
public List<Permission> getPermissions() {
return permissions;
}
public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
}
- BasePojo类
package com.carforu.bean;
import java.io.Serializable;
import java.util.Date;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.EL;
import org.nutz.dao.entity.annotation.Prev;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.random.R;
/**
* 共享字段,免得每个Pojo类都加创建时间和生成时间
* @author wendal
*
*/
public abstract class BasePojo implements Serializable {
private static final long serialVersionUID = 1L;
@Prev(els=@EL("$me.now()"))
@Column("created_time")
protected Date createdTime;
@Prev(els=@EL("$me.now()"))
@Column("modified_time")
protected Date modifiedTime;
public String toString() {
return String.format("/*%s*/%s", super.toString(), Json.toJson(this, JsonFormat.compact()));
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Date getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Date now() {
return new Date();
}
public String uuid() {
return R.UU32().toLowerCase();
}
}
- 查询
public List listAll() {
List list = dao().query(User.class, null); //这里debug的时候,发现list中的user都没有createdTime和updatedTime属性
return list;
}