Model.java代码如下
@Entity
@Table(name="tb_model")
public class Model extends IdEntity{
static final long serialVersionUID = 0L;
………
//返回model的treeType
@Transient
public String getTreeType() {
return "ml";
}
}
ModelTree.java代码如下
@Entity
@Table(name = "tb_modeltree")
public class ModelTree extends TreeEntity<ModelTree> implements HibernateTree,
PriorityInterface {
static final long serialVersionUID = 0L;
。。。。
//返回modeltree的treeType
@Transient
public String getTreeType() {
return "mt";
}
}
JsonUtils.write()方法修改如下
/**
* 配置json-lib需要的excludes和datePattern.
*
* @param excludes
* 不需要转换的属性数组
* @param datePattern
* 日期转换模式
* @return JsonConfig 根据excludes和dataPattern生成的jsonConfig,用于write
*/
public static JsonConfig configJson(String[] excludes, String datePattern) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
//配置需要转换的属性
if (name.equals("text") || name.equals("id")
|| name.equals("checked") || name.equals("leaf")
|| name.equals("treeType")) {
return false;
} else {
return true;
}
}
});
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.registerJsonValueProcessor(Date.class,
new DateJsonValueProcessor(datePattern));
return jsonConfig;
}