我在model定义中加了一个字段,
public class Node extends BaseNode<Node> {
public static final Node dao = new Node().dao();
private String deviceChannel;
public String getDeviceChannel() {
return deviceChannel;
}
public void setDeviceChannel(String deviceChannel) {
this.deviceChannel = deviceChannel;
}
}在controller 中json返回到前端,
public void getPageData(){
Page<Node> nodes = service.paginate(getParaToInt("page",1), getParaToInt("limit"));
List<Node> listNode = nodes.getList();
HashMap<String,String> map = chService.getChDevMap();
for(Node n :listNode){
n.setDeviceChannel(map.get(n.getChId()));
}
PageKit<Node> pageData = new PageKit<Node>(nodes);
//json返回中竟然没有新加的字段deviceChannel,???
renderJson(pageData);
}求教。json返回中竟然没有新加的字段deviceChannel,???
if (value instanceof Model) {Map map = com.jfinal.plugin.activerecord.CPI.getAttrs((Model)value);
return mapToJson(map, depth);
}
if (value instanceof Record) {
Map map = ((Record)value).getColumns();
return mapToJson(map, depth);
}
所以正确的姿势 >> 你要改为:
public class Node extends BaseNode<Node> {
public String getDeviceChannel() {
return get("deviceChannel");
}
public void setDeviceChannel(String deviceChannel) {
put("deviceChannel ", deviceChannel)
}
}
如果deviceChannel 是数据库的字段就用 set("deviceChannel", deviceChannel)
不是数据库的字段就用put(xx)