/**
* Generated by JFinal.
*/
@SuppressWarnings("serial")
public class Employee extends BaseEmployee<Employee> {
public static final Employee dao = new Employee().dao();
private Department dept = null;
public String getSkillJson() {
String skill = getSkill();
if (StrKit.isBlank(skill)) {
return JSONUtil.toJsonStr("[]");
}
System.out.println(skill);
return JSONUtil.toJsonStr(skill.split(","));
}
public Department getDept() {
System.out.println("this cid=" + this.getCid() + ",this id=" + this.getDid());
return CACHE.getDepartment(this.getCid(), this.getDid());
}
// 员工所在部门
public String getDeptName() {
Department d = CACHE.getDepartment(this.get("cid"), this.get("did"));
return d == null ? "" : d.getDeptName();
}
}使用Page<M>或者List<M>均无法读取到这几个属性值,直接使用Page<Employee>/List<Employee>是可以的。我写了一个公共的调用方法,子类都是继承自Model的,所在不想另外写了。请问下有什么办法吗?
我看了http://www.jfinal.com/feedback/3184这个帖子,如果设置了me.setJsonFactory(new FastJsonFactory()),程序挂了,而且这个是2018年的回复,不知道@JFinal有没有优化过。
我尝试加了以下代码
@Override
protected Map<String, Object> _getAttrs() {
// TODO Auto-generated method stub
Map<String, Object> attrs = super._getAttrs();
attrs.put("dept", getDept());
attrs.put("dept_name", getDeptName());
return attrs;
}结果又发现这个错误
this cid=null,this id=null
这个是打印语句,在这里调用了
public Department getDept() {
System.out.println("this cid=" + this.getCid() + ",this id=" + this.getDid());
return CACHE.getDepartment(this.getCid(), this.getDid());
}但使用Employee emp=Employee.dao.findById()又可以。
项目:JFinal
所以要配置成 FastJson:
me.setJsonFactory(new FastJsonFactory());
这些问题在文档中已经详细说明:
https://jfinal.com/doc/12-3