controller层
package com.wms.controller;
import com.wms.entity.Menu;
import com.wms.service.MenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class MenuController {
@Resource
private MenuService menu;
@GetMapping("/Menulist")
public List<Menu> Menulist(){
return menu.list();
}
}
entity (手动添加@TableField)
package com.wms.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="Menu对象", description="")
public class Menu implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
@ApiModelProperty(value = "菜单编码")
@TableField("menuCode")
private String menuCode;
@ApiModelProperty(value = "菜单名字")
@TableField("menuName") //和数据库表的字段一致,不加TableField字段中间会自动加下划线menu_Name
private String menuName;
@ApiModelProperty(value = "菜单级别")
@TableField("menuLevel")
private String menuLevel;
@ApiModelProperty(value = "菜单的父code")
@TableField("menuParentCode")
private String menuParentCode;
@ApiModelProperty(value = "点击触发的函数")
@TableField("menuClick")
private String menuClick;
@ApiModelProperty(value = "权限 0超级管理员,1表示管理员,2表示普通用户,可以用逗号组合使用")
@TableField("menuRight")
private String menuRight;
@TableField("menuComponent")
private String menuComponent;
@TableField("menuIcon")
private String menuIcon;
}
mapper
package com.wms.mapper;
import com.wms.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {
}
service
package com.wms.service;
import com.wms.entity.Menu;
import com.baomidou.mybatisplus.extension.service.IService;
public interface MenuService extends IService<Menu> {
}
impl
package com.wms.service.impl;
import com.wms.entity.Menu;
import com.wms.mapper.MenuMapper;
import com.wms.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wms.mapper.MenuMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.wms.entity.Menu">
<id column="id" property="id" />
<result column="menuName" property="menuName" />
<result column="menuLevel" property="menuLevel" />
<result column="menuParentCode" property="menuParentCode" />
<result column="menuClick" property="menuClick" />
<result column="menuRight" property="menuRight" />
<result column="menuComponent" property="menuComponent" />
<result column="menuIcon" property="menuIcon" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, menuName, menuLevel, menuParentCode, menuClick, menuRight, menuComponent, menuIcon
</sql>
</mapper>