问题起因:今天在做一个EasyUI 同步树的时候,在SpringMVC中用 @ResponseBody标签将List<tree> 集合转换成Json数据的时候,出现一些原因。
问题描述:1、tree对象有个List<tree>属性需要为空,这个是做树用的,下级没值当然不能有null了
代码:
[{"id":1,"text":"权限管理 ","state":"closed ","pid":-1,"children":[{"id":2,"text":"菜单管理","state":"open","pid":1,"children":null},{"id":3,"text":"角色管理","state":"open","pid":1,"children":null},{"id":4,"text":"用户管理","state":"open","pid":1,"children":null}]},{"id":5,"text":"33","state":"open","pid":-1,"children":null}] 解决方法;在实体类上使用 @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) 标签 就解决了! 加上标签后: [{"id":1,"text":"权限管理 ","state":"closed ","pid":-1,"children":[{"id":2,"text":"菜单管理","state":"open","pid":1},{"id":3,"text":"角色管理","state":"open","pid":1},{"id":4,"text":"用户管理","state":"open","pid":1}]},{"id":5,"text":"33","state":"open","pid":-1}]