//获取全部数据 List最终封装的数据:
{ "menuId": 1, "roleId": null, "menuName": "系统管理", "parentId": 0, "parentPath": "/system", "orderNum": "2", "menuUrl": "/system", "component": null, "isFrame": null, "redirect": "test", "menuType": "M", "hidden": "1", "perms": null, "icon": "icon-settings", "routeName": "system", "cacheable": "0", "affix": "0", "children": [ { "menuId": 100, "roleId": null, "menuName": "用户管理", "parentId": 1, "parentPath": "/system", "orderNum": "2", "menuUrl": "/system/user", "component": "system/user/index", "isFrame": null, "redirect": "test.com", "menuType": "C", "hidden": "1", "perms": null, "icon": "IconMenu", "routeName": "user", "cacheable": "0", "affix": "0", "children": null, "createTime": null }, { "menuId": 101, "roleId": null, "menuName": "角色管理", "parentId": 1, "parentPath": "/system", "orderNum": "3", "menuUrl": "/system/role", "component": "system/role/index", "isFrame": null, "redirect": "test", "menuType": "C", "hidden": "1", "perms": null, "icon": "IconMenu", "routeName": "role", "cacheable": "0", "affix": "0", "children": null, "createTime": null }, { "menuId": 102, "roleId": null, "menuName": "菜单管理", "parentId": 1, "parentPath": "/system", "orderNum": "4", "menuUrl": "/system/menu", "component": "system/menu/index", "isFrame": null, "redirect": "test.com", "menuType": "C", "hidden": "1", "perms": null, "icon": "IconMenu", "routeName": "menu", "cacheable": "0", "affix": "0", "children": null, "createTime": null }, { "menuId": 103, "roleId": null, "menuName": "部门管理", "parentId": 1, "parentPath": "/system", "orderNum": "1", "menuUrl": "/system/department", "component": "system/dept/index", "isFrame": null, "redirect": "test4.com", "menuType": "C", "hidden": "1", "perms": null, "icon": "IconMenu", "routeName": "department", "cacheable": "0", "affix": "0", "children": null, "createTime": null } ], "createTime": null }实体类代码
@JsonProperty注解主要用于实体类的属性上,作用可以简单的理解为在反序列化的时候给属性重命名(多一个名字来识别),我的使用是因为,在返回数据的时候把字段的is字样消除,通过注解给重命名;
个人建议boolean字段及含有判断的字段尽量避免is_开头,因为部分框架解析会引起序列化错误,因此可能造成代码的异常,详情可浏览阿里巴巴开发手册
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.extension.activerecord.Model; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; /** * @Project: uc * @Author: pangyq * @CreateTime: 2022-08-03 14:28 * @Description: TODO * @Version: 1.0 */ @Data public class Menu extends Model{ private static final long serialVersionUID = 1L; /** * 菜单ID */ @TableId(type = IdType.INPUT) private Long menuId; /** * 角色ID */ private Long roleId; /** * 菜单名称 */ private String menuName; /** * 父菜单ID */ private Long parentId; /** * 上级菜单 */ private String parentPath; /** * 显示顺序 */ private String orderNum; /** * 路由地址 */ private String menuUrl; /** * 组件路径 */ private String component; /** * 是否为外链(0是 1否) */ private String isFrame; /** * 外链地址 */ private String redirect; /** * 类型(M目录 C菜单 F按钮) */ private String menuType; /** * 菜单状态:0显示,1隐藏 */ private String hidden; /** * 权限字符串 */ private String perms; /** * 菜单图标 */ private String icon; /** * 路由名称 */ private String routeName; /** * 是否缓存(0是 1否) */ private String cacheable; /** * 是否固定标题栏(0是 1否) */ private String affix; /** * 子菜单 */ private List<Menu> children = new ArrayList<Menu>(); /** * 创建时间 */ private LocalDateTime createTime; private String badge; //@JsonProperty注解主要用于实体类的属性上,作用可以简单的理解为在反序列化的时候给属性重命名(多一个名字来识别) @JsonProperty(value = "isRootPath") private boolean isRootPath; @JsonProperty(value = "isSingle") private boolean isSingle; private String localFilePath; }