java代码转json格式 dtree展示时undefined
原创
©著作权归作者所有:来自51CTO博客作者wx6316c4e40e2ec的原创作品,请联系作者获取转载授权,否则将追究法律责任
dtree展示时 使用@RestController注解的方式
package com.cc.controller;
import com.cc.common.DataGridView;
import com.cc.common.DeptNode;
import com.cc.common.PageBean;
import com.cc.domain.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("dept")
public class DeptController {
@Autowired
private DeptService deptService;
//展示树形结构
@RequestMapping("buildLeftTree")
public DataGridView buildLeftTree(){
List<Dept>deptList=deptService.queryDeptList();
List<DeptNode>treeNodeList = new ArrayList<>();
for (Dept dept : deptList) {
treeNodeList.add(new DeptNode(dept.getId(),dept.getPid(),dept.getTitle()));
}
return new DataGridView(treeNodeList);
}
}
定义一个类
package com.cc.common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataGridView {
private Integer code =0;
private String msg ="";
private Long count=0L;
private Object data;
public DataGridView(Long count,Object data){
super();
this.count=count;
this.data=data;
}
public DataGridView(Object data){
super();
this.data=data;
}
}
报Uncaught TypeError:Cannot read property ‘code‘ of undefinedn时点击此文章