<file_sep>package com.taifan1.mapper;

import com.taifan1.domain.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 多
 */
@Mapper
public interface UserMapper {

    //查询出所有用户
    @Select("select * from user")
    List<User> getUser();

    //根据用户名模糊查询用户
    @Select("select * from user where name like CONCAT('%',#{name},'%')")
    List<User> likeSelectUser(@Param("name") String name);


    //添加用户
    @Insert("insert into user(id,name,password)values(#{id},#{name},#{password})")
    int addUser(User user);

    //修改用户
    @Update("update User set name=#{name},password=#{password} where id=#{id}")
    void updateUser(User user);

    //删除用户
    @Delete("delete from user where id=#{id}")
    void deleteUser(@Param("id") Integer id);

    //添加菜单
    @Insert("insert into menu(id,category)values(#{id},#{category})")
    int addmenu(menu menu);

    //查询出所有菜单
    @Select("select * from menu")
    List<menu> getmenu();

    //修改菜单
    @Update("update menu set category=#{category} where id=#{id}")
    void updatemenu(menu menu);

    //删除菜单
    @Delete("delete from menu where id=#{id}")
    void deletemenu(@Param("id") Integer id);

    //给用户赋予菜单，先查询
    @Select("select count(*) from us where menu_id=#{menu_id} and user_id = #{id} ")
    int selectUserByIdMenuId(@Param("id")Integer id,@Param("menu_id") Integer menu_id);

    //给用户赋予菜单
    @Insert("insert into us(menu_id,user_id) values (#{menu_id},#{uid}) ")
    @Results( value={
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="menu_id", property="menu_id", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_id", property="user_id", jdbcType=JdbcType.VARCHAR),
            //column是数据库表的字段，property是类表中的字段
    })
    int addUserMenu(@Param("uid")Integer id,@Param("menu_id") Integer menu_id);

    //传用户id 查询出菜单
    @Select("SELECT * FROM menu cc " +
            " left join us on us.menu_id = cc.id" +
            " where us.user_id = #{id} ")
    List<menu> getmenuById(Integer id);

    //添加功能
    @Insert("insert into operation(function)values(#{function})")
    int addoperation(operation operation);

    //功能查询
    @Select("select * from operation")
    List<operation> gitopeation();

    //删除功能
    @Delete("delete from operation where id=#{id}")
    void deleteoperation(@Param("id") Integer id);

    //赋予菜单功能
    @Update("update operation set mu_id=#{menu_id} where id=#{operation_id}")
    int addMenuOperation(@Param("operation_id") Integer id,@Param("menu_id") Integer menu_id);

    //根据菜单id查询出所对应的功能
    @Select("SELECT * FROM operation WHERE mu_id = #{id}")
    List<operation> getoperationById(Integer id);

    //整合sql语句 直接根据id查出用户功能

    @Select("select * from operation o left join menu on menu.id = o.id " +
            " left join us on us.menu_id = menu.id " +
            "left join user on us.user_id = user.id where us.user_id=#{id} ")
    List<operation> getOperationUserById(Integer id);



}


<file_sep>package com.taifan1.domain;

import io.swagger.annotations.ApiModelProperty;

/**
 * 操作表 多
 */
public class operation {
    @ApiModelProperty(value="id",hidden=true)
    private Integer id;
    private String function;//功能
    @ApiModelProperty(value="menus数组",hidden=true)
    private menu menus;

    public menu getMenus() {
        return menus;
    }

    public void setMenus(menu menus) {
        this.menus = menus;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFunction() {
        return function;
    }

    public void setFunction(String function) {
        this.function = function;
    }

    @Override
    public String toString() {
        return "operation{" +
                "id=" + id +
                ", function='" + function + '\'' +
                ", menus=" + menus +
                '}';
    }
}
<file_sep>package com.taifan.mapper;

import com.taifan.domain.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper {
//@ResultMap的用法。当这段@Results代码需要在多个方法用到时，为了提高代码复用性，
// 我们可以为这个@Results注解设置id，然后使用@ResultMap注解来复用这段代码。
    //查询所有
    @Select({"select * from user"})
    @Results(id="studentMap", value={
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.INTEGER),
            @Result(column="created_by", property="createdby", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_type", property="type",jdbcType=JdbcType.VARCHAR)//column是数据库表的字段，property是类表中的字段
    })
    List<User> initial();

    @Select({"select * from user"})
          @ResultMap(value="studentMap")
    List<User> findAll();
    //第根据id查询
        @Select({"select *  from user where id = #{id}"})
        @ResultMap(value="studentMap")
        List<User> findid(@Param("id") Integer id);

    //用户删除delete from <表名> [where <删除条件>]例：delete from a where name='开心朋朋'（删除表a中列值为开心朋朋的行）
    @Delete("Delete FROM USER WHERE id = #{id}")
    int removeUser(@Param("id") Integer id);//@Param("id")注解表示给该注解后面的变量去一个参数名称，对应@Delete注解中的#{id}
    //修改
    @Update("UPDATE USER SET name=#{name},password=#{<PASSWORD>},created_by=#{createdby},user_type=#{type} WHERE id=#{id}")
    void upDate1(User user);
    //用户添加第2中方法
    @Insert("insert into user(id,name,password,created_by,user_type)values(#{id},#{name},#{password},#{createdby},#{type})")
    int addUser1(User user);


    //传用户名密码直接判断
    @Select("select * from user where name=#{name} and password = #{password}")
    @ResultMap(value="studentMap")
    List<User> login5(@Param("name")String name,@Param("password") Integer password);


}

<file_sep>package com.taifan1.controller;

import com.alibaba.fastjson.JSONObject;
import com.taifan1.domain.User;
import com.taifan1.domain.menu;
import com.taifan1.domain.operation;
import com.taifan1.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Api(value = "用户controller",tags={"用户操作接口"})
@RestController
@RequestMapping(value ="/user")
public class UserController {
    @Autowired
    private UserService userService;
    private PageResults<User> pageResults1 ;

    //分页模糊查询
    @ApiOperation(value = "分页查询所有用户",notes = "分页查询所有用户")
    @GetMapping(value = "/Paging", produces = "application/json;charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="name",value ="用户名",required = true,dataType ="String",paramType = "query"),
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name="pageSize", value="每页显示的条数", dataType = "Integer",paramType="query")})
    public String getUserPaging(@RequestParam String name,@RequestParam int pageNum, @RequestParam int pageSize)throws Exception{
        List<User> booklist = userService.getUser(name,pageNum,pageSize);
        List<User> booklist1 = userService.getUser();
        int count = booklist1.size();
        JSONObject result = new JSONObject();
        result.put("pageNum",pageNum);
        result.put("pageSize", pageSize);
        result.put("count", count);
        result.put("data",booklist);
        return result.toJSONString();
    }


    //查询所有用户
    @ApiOperation(value = "查询所有用户",notes = "查询所有用户")
    @GetMapping(value = "")
    public List<User> getUser(){
        List<User> booklist = userService.getUser();
        System.out.println(booklist);
        return booklist;
    }

    //根据用户名模糊查询用户
    @ApiOperation(value = "模糊查询用户",notes = "根据用户名模糊查询用户")
    @GetMapping(value = "/like")
    @ApiImplicitParam(name ="name",value ="用户名",required = true,dataType ="String",paramType = "query")
    public List<User> likeSelectUser(@RequestParam String name){
      return userService.likeSelectUser(name);

    }

    //添加用户
    @ApiOperation(value = "添加用户",notes = "添加用户")
    @PostMapping(value = "")
    public int addUser(@ApiParam(value = "用户各个属性") @RequestBody User user){
        userService.addUser(user);
        user.getId();
        System.out.println("返回的id"+user.getId());
        return user.getId();
    }

    //修改用户
    @ApiOperation(value = "修改用户",notes = "修改用户")
    @PutMapping(value = "")
    public void  updateUser(@ApiParam(value = "用户的各个属性") @RequestBody User user ){
        userService.updateUser(user);
    }

    //删除用户
    @ApiOperation(value = "删除用户",notes = "删除用户")
    @DeleteMapping(value = "/{id}")
    @ApiImplicitParam(name ="id",value ="用户的id",required = true,dataType ="Integer",paramType = "path")
    public void deleteUser(@PathVariable("id") Integer id){
        userService.deleteUser(id);
    }

    //添加菜单
    @ApiOperation(value = "添加菜单",notes = "添加菜单")
    @PostMapping("/menu")
    public void addMenu( @RequestBody menu menu){
        userService.addmenu(menu);
    }

    //查询所有菜单
    @ApiOperation(value = "查询所有菜单",notes = "查询所有菜单")
    @GetMapping(value = "/menu")
    public List<menu> getMenu(){
        List<menu> booklist1 = userService.getmenu();
        System.out.println(booklist1);
        return booklist1;
    }

    //修改菜单
    @ApiOperation(value="修改菜单",notes = "修改菜单")
    @ApiImplicitParam(name ="menu",value ="menu的属性",dataType ="menu",paramType = "body")
    @PutMapping(value = "/menu")
    public void updateMenu(@RequestBody  menu menu){
        userService.updatemenu(menu);
    }

    //删除菜单
    @ApiOperation(value = "删除菜单",notes = "删除菜单")
    @DeleteMapping("/menu/{id}")
    public void deleteMenu(@PathVariable Integer id){
        userService.deletemenu(id);
    }

    //给用户赋予菜单
    @ApiOperation(value = "给用户赋予菜单",notes = "给用户赋予菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name="menu_id", value="菜单id数组集", required=true, paramType="query" ,allowMultiple=true, dataType = "String")})
    @PutMapping("/get")
    public void addUserMenu(@RequestParam Integer id,@RequestParam Integer[] menu_id){
        for (int b : menu_id) {
            Integer int1 =  userService.selectUserByIdMenuId(id,b);
            System.out.println("查出的数据"+int1);
            if (int1==null||int1 ==0){
                int a = userService.addUserMenu(id, b);
            }else{
                System.out.println("重复");
            }
        }
    }

    //传用户id查询出菜单
    @ApiOperation(value = "传用户id查询出菜单",notes = "查询用户管理的菜单")
    @GetMapping("/menu/{id}")
        public List<menu> getMenuById(@PathVariable Integer id){
        List<menu> booklist = userService.getmenuById(id);
        return booklist;
    }

    //添加功能
    @ApiOperation(value = "添加功能",notes = "添加功能")
    @PostMapping("/operation")
    public void addOperation( @RequestBody operation operation){
        userService.addoperation(operation);
    }

    //查询所有的功能
    @ApiOperation(value = "查询所有的功能",notes = "查询所有的功能")
    @GetMapping(value = "/operation")
    public List<operation> gitOpeation(){
        List<operation> sir = userService.gitopeation();
        return sir;
    }

    //删除功能
    @ApiOperation(value = "删除功能",notes = "删除功能")
    @DeleteMapping("/operation/{id}")
    public void deleteOperation(@PathVariable Integer id){
        userService.deleteoperation(id);
    }

    //给菜单赋予功能
    @ApiOperation(value = "给菜单赋予功能",notes = "给菜单赋予功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name="menu_id", value="菜单的id", required=true, dataType = "Integer",paramType="query" ),
            @ApiImplicitParam(name = "id",value = "功能的id数组集",required = true,dataType = "String",allowMultiple=true,paramType = "query")})
    @PutMapping("/operation")
    public void addMenuOperation(@RequestParam Integer[] id,@RequestParam Integer menu_id){
        for (int a : id) {
                int a1 = userService.addMenuOperation(a,menu_id);
        }
    }

    //传菜单id,查询出功能
    @ApiOperation(value = "传菜单id查询出对应的功能",notes = "传菜单id,查询出功能")
    @GetMapping("/menu/query/{id}")
    public List<operation> getOperationById(@PathVariable Integer id){
        List<operation> book_list1= userService.getoperationById(id);
        return book_list1;
    }

    //整合
    //传用户id 查询出菜单和功能
    @ApiOperation(value = "传用户id 查询出菜单和功能",notes = "传用户id 查询出菜单和功能")
    @GetMapping("/yonghu/{id}")
    public List<menu> getMenuOperationById(@PathVariable("id") Integer id){
        //传用户id 查询出菜单
        List<menu> booklist = userService.getmenuById(id);
        System.out.println(booklist);
        userService.traverse(booklist);
        return userService.traverse(booklist);
    }

    //根据用户id 直接查询出所对应的功能
    @ApiOperation(value = "根据用户id 直接查询出所对应的功能",notes = "根据用户id 直接查询出所对应的功能")
    @GetMapping("get/{id}")
    public List<operation> getOperationUserById(@PathVariable("id") Integer id){
        List<operation> maplist1 = userService.getOperationUserById(id);
        return maplist1;
    }

}
<file_sep>package com.taifan1.domain;

import java.util.List;

/**
 * 订单
 */
public class Orde {

    private Integer id;			// id
    private String code;	    //
    private Integer total;	// 密码

    //订单和商品之间是多对多的关系
    private List<Commodity> commodity;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public List<Commodity> getCommodity() {
        return commodity;
    }

    public void setCommodity(List<Commodity> commodity) {
        this.commodity = commodity;
    }

    @Override
    public String toString() {
        return "Orde{" +
                "id=" + id +
                ", code='" + code + '\'' +
                ", total=" + total +
                ", commodity=" + commodity +
                '}';
    }
}
<file_sep>rootProject.name = 'taifan'

<file_sep>package com.junit;
import com.taifan.controller.UserController;
import com.taifan.service.UserService;
import com.taifan.service.UserServiceimpl;
import com.taifan.ZhuLei;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ZhuLei.class )
@WebAppConfiguration// 由于是Web项目，Junit需要模拟ServletContext，因此我们需要给我们的测试类加上@WebAppConfiguration。
public class UsercontrollerTest1 {
    @Autowired
    private UserController userController;
    @Autowired
    private UserService userService;
    @Autowired
    private UserServiceimpl userServiceimpl;
/*    @Autowired
    private UserMapper userMapper;*/

    @Test
    public void testchaxun() {
        System.out.println("测试userController.查询方法");
        //userController.chaxun();
        System.out.println("测试完成");
    }



    // 在所有方法执行之前执行
    @BeforeClass
    public static void globalInit() {
        System.out.println("初始化所有的方法");//初始化所有的方法……
    }
    @AfterClass
// 在所有方法执行之后执行
    public static void globalDestory() {

        System.out.println("毁掉所有的方法");//毁掉所有的方法……
    }

    @Before
// 在每个测试方法之前执行
    public void setUp() {
        System.out.println("在每个测试方法之前执行");
        userController = new UserController();
        userService = new UserServiceimpl();
    }

    @After
// 在每个测试方法之后执行
    public void tearDown() {
        System.out.println("在每个测试方法之后执行");
    }



/*    @Test
    public void Testchu() {
        System.out.println("测试  userMapper.findAll();;方法");
        userMapper.findAll();
    }*/


}
<file_sep>package com.education.mapper;

import com.education.domain.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户
 */

@Mapper
public interface UserMapper {

    //获取所有用户
    @Select("select * from user")
    List<User> getAllUser();

    //分页获取所有用户
    @Select("select * from user where name like CONCAT('%',#{name},'%')")
    List<User> getUser(@Param("name") String name);

    //添加用户
    /**
     *
     * keyProperty: 表示将select返回值设置到该类属性中
     * resultType: 返回类型
     * before: 是否在insert之前执行
     * statement: 自定义子查询 把生成的uuid去掉-和空
     */
    @SelectKey(keyProperty = "id",resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    //@Options(keyProperty = "user.id", useGeneratedKeys = true)
    @Insert("Insert into user(id,name,password)values(#{id},#{name},#{password})")
    int addUser(User user);

    //修改用户
    @Update("update user set name=#{name},password=#{password} where id=#{id}")
    void upDateUser(User user);

    //删除用户
    @Delete("delete from user where id=#{id}")
    void deleteUser(@Param("id") String id);

    //给用户赋予角色
    //先查询是否已经赋值过
    @Select("select count(*) from user_role where user_id=#{userId} and role_id=#{roleId}")
    int selectUserByIdRoleById(@Param("userId")String id,@Param("roleId") String roleId);
    //赋角色
    @SelectKey(keyProperty = "id",resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Insert("insert into user_role(id,role_id,user_id) values (#{id},#{roleId},#{userId}) ")
    int addUserRole(@Param("userId")String id,@Param("roleId") String roleId);

    //根据用户id查询对应的角色
    @Select("select * from Role r " +
            "left join user_role ur on ur.role_id = r.id " +
            "where ur.user_id = #{id}")
    List<Role> getUserById(String id);




    /*//批量导入
    @Insert({ "<script>",
            "insert into event(id,summary,description,location,start_time,end_time,time_zone,event_type,action_type,notice_time,", "reminders,recurrence,notice_status,event_priority,event_status,share_status,creator_id,calendar_id,share_event_id,origin_event_id,", "finish_message,delete_reason,etag,expire_date,event_shared_date,split_id,create_time,update_time) ",
            "values",
            "<foreach item ='event' collection = 'list' separator = ','>",
            "(#{event.id},#{event.summary},#{event.description},#{event.location},#{event.startTime},#{event.endTime},#{event.timeZone},#{event.eventType},#{event.actionType},#{event.noticeTime},#{event.reminders},",
            "#{event.recurrence},#{event.noticeStatus},#{event.eventPriority},#{event.eventStatus},#{event.shareStatus},#{event.creatorId},#{event.calendarId},#{event.shareEventId},#{event.originEventId},#{event.finishMessage},#{event.deleteReason},", "#{event.etag},#{event.expireDate},#{event.eventSharedDate},#{event.splitId},#{event.createTime},#{event.updateTime})",
            "</foreach>",
            "</script>" })
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int saveAll(@Param("list") List<Event> list);*/


    //导入Excel表，解析，字段赋值，存储

    @Select(" SELECT count(*) FROM user WHERE name=#{name}")
    int selectByName(String name);

    @Insert("insert into util(name,phone,address,enrol_date,des)values(#{name},#{phone},#{address},#{enrolDate},#{des})")
    void addutil(Util userResord);

    @Update("update util set phone=#{phone},address=#{address},enrol_date=#{enrolDate},des=#{des} where name = #{name}")
    Util upDateutil(Util userResord);

    //从excel中获取的值添加到数据库
    @Insert("insert into person(name,sex,birthday,age)values(#{name},#{sex},#{birthday},#{age})")
    void addText(Person person);

    //获取Person数据
    //获取所有用户
    @Select("select * from person")
    List<Person> getAllPerson();




}
<file_sep>rootProject.name = 'taifan1'

<file_sep>package com.taifan.domain;

public class User{

   // @ApiModelProperty(value="id数组",hidden=true) //隐藏id
    private Integer id;			// id
    private String name;	    // 登录英文名
    private Integer password;	// 密码
    private String createdby;   //登录中文名 需要驼峰转换
    private String type;//

    public User() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPassword() {
        return password;
    }

    public void setPassword(Integer password) {
        this.password = <PASSWORD>;
    }

    public String getCreatedby() {
        return createdby;
    }

    public void setCreatedby(String createdby) {
        this.createdby = createdby;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password=" + <PASSWORD> +
                ", createdby='" + createdby + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}
<file_sep>package com.education;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//@ComponentScan//启动类 所在的包的路径
@MapperScan("com.education.mapper")//springBoot中集成mybates可以让别的类进行引用
@EnableAsync//注解可以异步执行，就是开启多线程的意思在方法上写@Async
@SpringBootApplication(scanBasePackages = "com.education")//：包含@EnableAutoConfiguration、@ComponentScan、@SpringBootConfiguration申明让springboot自动给程序必要的配置
@EnableWebMvc//用于启动springMVC特性
@EnableSwagger2
public class ZhuLei extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ZhuLei.class);
    }//这里继承SpringBootServletInitializer 并重写其中的configure方法目的是使用Spring框架的Servlet3.0支持。并且允许我们可以配置项目从serclet容器中启动

    public static void main(String[] args) {
        SpringApplication.run(ZhuLei.class,args);
    }
}
<file_sep>package com.education.controller;

import com.education.domain.Menu;
import com.education.domain.MenuAfter;
import com.education.domain.Resources;
import com.education.service.MenuService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "菜单controller",tags = {"菜单操作接口"})
@RestController
@RequestMapping(value = "/Menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    //查询所有菜单显示树状
    @ApiOperation(value = "查询所有菜单",notes = "查询所有菜单显示树状")
    @GetMapping(value = "")
    public Menu getMenu(){
       int me = menuService.getMenuAll();
        if (me == 0) {
            return null;
        }else {
        Menu menu = menuService.getMenu2();
        return getMenuByIdAll(menu.getId());
        }
    }

    //根据id查询对应的下级菜单
    @ApiOperation(value = "根据id查询对应的下级菜单",notes = "根据id查询对应的下级菜单")
    @GetMapping(value = "/{parentid}")
    public Menu getMenuByIdAll(String id){

        //根据id获取根节点对象(SELECT * FROM tb_tree t WHERE t.cid=?)
        Menu menu = menuService.getMenu1(id);
        //查询id下的所有子节点(SELECT * FROM tb_tree t WHERE t.pid=?)
        List<Menu> list1 = menuService.getMenu(id);
        //遍历子节点
        for(Menu menu1 : list1){
            Menu n = getMenuByIdAll(menu1.getId()); //递归
            menu.getNodes().add(n);
        }
        return menu;
    }

    //添加菜单
    @ApiOperation(value = "添加菜单",notes = "添加菜单")
    @PostMapping(value = "")
    public void addMenu(@ApiParam(value = "菜单的各个属性") @RequestBody MenuAfter menuAfter){
        menuService.addMenu(menuAfter);
    }

    //修改菜单
    @ApiOperation(value = "修改菜单",notes = "修改菜单")
    @PutMapping(value = "")
    public void upDateMenu(@ApiParam(value = "菜单的各个属性")@RequestBody MenuAfter menuAfter){
        menuService.upDateMenu(menuAfter);
    }

    //删除菜单
    @ApiOperation(value = "删除菜单",notes = "根据id删除菜单")
    @DeleteMapping(value = "/{id}")
    @ApiImplicitParam(name = "id",value = "菜单id",required = true,dataType = "String",paramType = "path")
    public void deleteMenu(@PathVariable String id){
        menuService.deleteMenu(id);
    }

    //给菜单赋予资源
    @ApiOperation(value = "给菜单赋予资源",notes = "给菜单赋予资源")
    @PostMapping(value = "/MenuResources")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "菜单id",required = true,dataType = "String",paramType ="query"),
            @ApiImplicitParam(name = "resourcesId",value = "资源id",required = true,dataType = "String",allowMultiple = true,paramType ="query")
    })
    public void addMenuResources(@RequestParam String id,@RequestParam String[] resourcesId){
        for (String a : resourcesId){
            //先判断是否已经赋值过
          Integer int2 = menuService.selectMenuByIdResourcesById(id,a);
            if (int2 == 0) {
                //赋予资源
                menuService.addMenuResources(id,a);
            }else {
                System.out.println("重复");
            }
        }
    }

    //根据菜单id查询对应的资源
    @ApiOperation(value = "根据菜单id查询对应的资源",notes = "根据菜单id查询对应的资源")
    @GetMapping(value = "/Menu/{id}")
    @ApiImplicitParam(name = "id",value = "菜单id",required = true,dataType = "String",paramType = "path")
    public List<Resources> getMenuById(@PathVariable String id){
        return menuService.getMenuById(id);
    }

}
<file_sep>package com.taifan1.domain;

import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * 菜单 一
 */
public class menu {
    private Integer id;
    private String category;//菜单
    //private List<User> users;//菜单和用户是多对多的关系
    @ApiModelProperty(value="menus数组",hidden=true)
    private List<operation> operation;//菜单和操作表 一对多 在一的一方引入多的一方 引入集合；

    //菜单和用户之间是多对多的关系
   // private List<User> users;

    //菜单和用户之间是多对多的关系
   // private List<User> users;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public List<com.taifan1.domain.operation> getOperation() {
        return operation;
    }

    public void setOperation(List<com.taifan1.domain.operation> operation) {
        this.operation = operation;
    }


    @Override
    public String toString() {
        return "menu{" +
                "id=" + id +
                ", category='" + category + '\'' +
                ", operation=" + operation +
                '}';
    }
}
<file_sep>package com.education.service;

import com.education.domain.Menu;
import com.education.domain.MenuAfter;
import com.education.domain.Resources;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface MenuService {

    //查询所有菜单
    int getMenuAll();

    //查询根节点
    Menu getMenu2();

    //根据id获取根节点对象
    Menu getMenu1(String id);

    //查询id下的所有子节点
    List<Menu> getMenu(String id);

    //添加菜单
    void addMenu(MenuAfter menuAfter);

    //修改菜单
    void upDateMenu(MenuAfter menuAfter);

    //删除菜单
    void deleteMenu(String id);

    //给菜单赋予资源
    //先查询是否已经赋值过
    int selectMenuByIdResourcesById(String id,String resourcesId);
    //赋资源
    int addMenuResources(String id,String resourcesId);

    //根据菜单id查询对应的资源
    List<Resources> getMenuById(String id);

}
<file_sep>package com.taifan1;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Configuration注解，表明它是一个配置类，
 * @EnableSwagger2开启swagger2。
 * apiINfo()配置一些基本的信息。
 * apis()指定扫描的包会生成文档。
 */

@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2017-10-18T18:27:24.331+08:00")

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot 测试使用 Swagger2 构建RESTful API")
                .description("API 描述")
                .license("")
                .licenseUrl("http://unlicense.org")
                .termsOfServiceUrl("")
                .version("1.0.0")
                .contact(new Contact("","", ""))
                .build();
    }

    @Bean
    public Docket customImplementation(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.taifan1.controller"))//扫描的包
                .build()
                //.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
                //.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
                .apiInfo(apiInfo());
    }


/*  swagger通过注解表明该接口会生成文档，包括接口名、请求方法、参数、返回信息的等等。
    @Api：修饰整个类，描述Controller的作用
        1. tags：可以使用tags()允许您为操作设置多个标签的属性，而不是使用该属性。
        2. description：可描述描述该类作用。
    @ApiOperation：描述一个类的一个方法，或者说一个接口，用在方法上，说明方法的作用
        value: 表示接口名称
        notes: 表示接口详细描述
    @ApiParam()用于方法，参数，字段说明； 表示对参数的添加元数据（说明或是否必填等）
    @ApiProperty：用对象接收参数时，描述对象的一个字段
    @ApiResponse：用在@ApiResponses中，一般用于表达一个错误的响应信息
        code：状态码
        message：返回自定义信息
        response：抛出异常的类
    @ApiResponses：用于方法，一个允许多个ApiResponse对象列表的包装器。
        @ApiResponses(value = {
            @ApiResponse(code = 500, message = "2001:因输入数据问题导致的报错"),
            @ApiResponse(code = 500, message = "403:没有权限"),
            @ApiResponse(code = 500, message = "2500:通用报错（包括数据、逻辑、外键关联等，不区分错误类型）")})
    @ApiIgnore：使用该注解忽略这个API，表示该接口函数不对swagger2开放展示
    @ApiError ：发生错误返回的信息
    @ApiParamImplicitL：一个请求参数
    @ApiParamsImplicit 多个请求参数
    方法级安全控制
    @PreAuthoriz进入方法之前先满足括号内的内容
    @PostAuthorize一般用于对返回的值做验证授权
    参数描述信息
    @ApiImplicitParams各个参数的各个属性，内部须用到@ApiImplicitParam注解
    @GetMapping/Postmapping相当于@RequestMapping(method = RequestMethod.GET/POST)
    @ApiImplicitParams：用在方法上包含多个 @ApiImplicitParam：
      例如：@ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "book's name", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "date", value = "book's date", required = false, dataType = "string", paramType = "query")})
    @ApiImplicitParam：用在@ApiImplicitParams注解中，指定一个请求参数的各个方面 ，给出某请求参数（来自浏览器前台）的各个属性
        name：参数名
        value：参数的描述
        required：参数是否必须传
        dataType：参数类型
        defaultValue：参数的默认值
        paramType：参数位置
            header 参数在request headers 里边提交 对应获取参数值的注解：@RequestHeader
            query  直接跟参数完成自动映射赋值       对应获取参数值的注解：@RequestParam
            path   以地址的形式提交数据            对应获取参数值的注解： @PathVariable
            body   以流的形式提交 仅支持POST        对应获取参数值的注解: @RequestBody
            form   对应以form表单的形式提交         仅支持POST
    @ApiModel()用于类 ；表示对类进行说明，用于参数用实体类接收
        value–表示对象名
        description–描述
    都可省略
    @ApiModelProperty()用于方法，字段； 表示对model属性的说明或者数据操作更改
        value–字段说明
        name–重写属性名字
        dataType–重写属性类型
        required–是否必填
        example–举例说明
        hidden–隐藏
    @ResponseHeader：
        响应头设置，使用方法。
    */

}
<file_sep>package com.education.mapper;

import com.education.domain.Menu;
import com.education.domain.Resources;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 菜单
 */
@Mapper
public interface MenuMapper {

    //查询所有菜单
    @Select("select count(*) from menu")
    int getMenuAll();

    //查寻根节点
    @Select("select * from menu m where m.parent_id = 0 ")
    Menu getMenu2();

    //根据id获取根节点对象
    @Select("select * from menu where id =#{id}")
    Menu getMenu1(String id);

    //查询id下的所有子节点
    @Select("select * from menu m where m.parent_id = #{id}")
    List<Menu> getMenu(String id);

    //添加菜单
    /**
     *主键由uuid函数生成
     * keyProperty: 表示将select返回值设置到该类属性中
     * resultType: 返回类型
     * before: 是否在insert之前执行
     * statement: 自定义子查询 把生成的uuid去掉-和空
     * useGeneratedKeys="true"把新增加的主键赋值到自己定义的keyProperty（id）
     */
    @SelectKey(keyProperty = "id",resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Insert("insert into menu(id,code,name,icon,url,parent_id,type,`order`,status,description,created_by,created_on,updated_by,is_leaf,default_menus)values" +
            "(#{id},#{code},#{name},#{icon},#{url},#{parentid},#{type},#{order},#{status},#{description},#{createdby},#{createdon},#{updatedby},#{isleaf},#{defaultmenus})")//当使用的字段名、表名与MySQL关键字冲突时，如果不加反引号``，无法执行成功。
    void addMenu(Menu menu);

    //修改菜单
    @Update("update menu set code=#{code},name=#{name},icon=#{icon},url=#{url},parent_id=#{parentid},type=#{type},`order`=#{order},status=#{status},description=#{description}," +
            "created_by=#{createdby},created_on=#{createdon},updated_by=#{updatedby},updated_on=#{updatedon},is_leaf=#{isleaf},default_menus=#{defaultmenus} where id=#{id}")
    void upDateMenu(Menu menu);

    //删除菜单
    @Delete("delete from menu where id=#{id}")
    void deleteMenu(@Param("id") String id);

    //给菜单赋予资源
    //先查询是否已经赋值过
    @Select("select count(*) from menu_resources where menu1_id=#{menuId} and resources_id=#{resourcesId}")
    int selectMenuByIdResourcesById(@Param("menuId")String id,@Param("resourcesId") String resourcesId);

    //赋资源
    @SelectKey(keyProperty = "id",resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Insert("insert into menu_resources(id,menu1_id,resources_id) values (#{id},#{menuId},#{resourcesId})")
    int addMenuResources(@Param("menuId")String id,@Param("resourcesId") String resourcesId);

    //根据菜单id查询对应的资源
    @Select("select * from resources r " +
            "left join menu_resources mr on mr.resources_id = r.id" +
            " where mr.menu1_id = #{id}")
    List<Resources> getMenuById(String id);

}
<file_sep>package com.taifan1.service;


import com.taifan1.domain.*;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public interface UserService {
    //查询所有用户
    List<User> getUser();

    //分页查询
    List<User> getUser(String name,int pageNum, int pageSize) throws Exception;

    //模糊查询用户
    List<User>likeSelectUser(String name);

    //添加用户
    int addUser(User user);

    //修改用户
    void updateUser(User user);

    //删除用户
    void deleteUser(Integer id);

    //添加菜单
    int addmenu(menu menu);

    //查询所有菜单
    List<menu> getmenu();

    //修改菜单
    void updatemenu(menu menu);

    //删除菜单
    void deletemenu(Integer id);

    //给用户赋予菜单 ,先查询
    int selectUserByIdMenuId(Integer id,Integer menu_id);
    int addUserMenu(Integer id,Integer menu_id);

    //传用户id 查询出菜单
    List<menu> getmenuById(int id);

    //添加功能
    int addoperation(operation operation);

    //功能查询
    List<operation> gitopeation();

    //删除功能
    void deleteoperation(Integer id);

    //赋予菜单功能
    int addMenuOperation(Integer id,Integer menu_id);

    //根据菜单id查询出所对应的功能
    List<operation> getoperationById(int id);
    List<menu> traverse(List<menu> booklist);

    //根据用户id直接查出功能
    List<operation> getOperationUserById(int id);

}
<file_sep>package com.taifan1.mapper;

import com.taifan1.domain.Commodity;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 一
 */
public interface CommodityMapper {

    @Select("SELECT * FROM Commodity WHERE ID = #{id} ")
    CommodityMapper selectById(Integer id);


    @Select("SELECT * FROM Commodity WHERE id IN "
            +"(SELECT commodity_id FROM item WHERE order_id = #{id} ) ")
    List<Commodity> selectByOrderId(Integer order_id);
}
<file_sep>/*
Navicat MySQL Data Transfer

Source Server         : xt1
Source Server Version : 50716
Source Host           : localhost:3306
Source Database       : permissions

Target Server Type    : MYSQL
Target Server Version : 50716
File Encoding         : 65001

Date: 2018-12-29 15:57:37
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `menu`
-- ----------------------------
DROP TABLE IF EXISTS `menu`;
CREATE TABLE `menu` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `category` varchar(40) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of menu
-- ----------------------------
INSERT INTO `menu` VALUES ('1', '教学过程');
INSERT INTO `menu` VALUES ('2', '资源库');
INSERT INTO `menu` VALUES ('3', '管理仓库');

-- ----------------------------
-- Table structure for `operation`
-- ----------------------------
DROP TABLE IF EXISTS `operation`;
CREATE TABLE `operation` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `function` varchar(20) DEFAULT NULL,
  `mu_id` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `mu_id` (`mu_id`),
  CONSTRAINT `mu_id` FOREIGN KEY (`mu_id`) REFERENCES `menu` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of operation
-- ----------------------------
INSERT INTO `operation` VALUES ('1', '添加', '2');
INSERT INTO `operation` VALUES ('2', '删除', '2');
INSERT INTO `operation` VALUES ('3', '修改', null);
INSERT INTO `operation` VALUES ('4', '查询', '3');

-- ----------------------------
-- Table structure for `us`
-- ----------------------------
DROP TABLE IF EXISTS `us`;
CREATE TABLE `us` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `menu_id` int(10) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `menu_id` (`menu_id`),
  CONSTRAINT `menu_id` FOREIGN KEY (`menu_id`) REFERENCES `menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of us
-- ----------------------------
INSERT INTO `us` VALUES ('1', '2', '1');
INSERT INTO `us` VALUES ('2', '1', '2');
INSERT INTO `us` VALUES ('3', '2', '2');
INSERT INTO `us` VALUES ('4', '4', '2');
INSERT INTO `us` VALUES ('5', '4', '3');

-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  `password` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '张三', '1111');
INSERT INTO `user` VALUES ('2', '李四', '222');
INSERT INTO `user` VALUES ('3', 'ooo', '424');
INSERT INTO `user` VALUES ('4', 'xiaoming', '555');
<file_sep>package com.taifan.service;
import com.taifan.domain.User;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public interface UserService {
    //用户查询
    List<User> getAll();
    //根据id查询
    List<User> getAllid(int id);
    //用户删除
    public void delete(int id);
    //修改第二种方法
    public void upDate1(User user);
    //用户添加
    int addUser(User user);
    //传用户名密码直接判断
    List<User> login5(String name,Integer password);
}
<file_sep>package com.taifan.controller;

import com.taifan.domain.User;
import com.taifan.service.UserService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * 用户功能模块
 */

@Api(value = "用户controller",tags={"用户操作接口"})
@RestController
@RequestMapping(value ="/user")
@EnableSwagger2
public class UserController {
    /* *
     * 自动注入UserService
     * */
    @Autowired
    private UserService userService;
    private static final Logger logger= LoggerFactory.getLogger(UserController.class);
    //用户查询
    @ApiOperation(value = "查询", notes = "查询数据库中所有的学生信息")
    @GetMapping(value = "")//替代@RequestMapping(value="", method = RequestMethod.GET)
    public List<User> chaxun(){
        List<User> book_list = userService.getAll();
        return book_list;
    }
    //根据id查询
    @ApiOperation(value = "查询用户",notes = "根据url的id来查询用户")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "Integer",paramType = "path")
    @GetMapping("/{id}")
    public List<User>  findid(@PathVariable("id") Integer id){
        List<User> book_list= userService.getAllid(id);
        return book_list;
    }
    //用户删除
    @ApiOperation(value = "删除用户",notes = "根据url的id来指定删除用户")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "Integer",paramType = "path")
    @DeleteMapping("/{id}")//@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable("id") Integer id){
        System.out.println("进入删除方法");
        userService.delete(id);
        return "success";
    }
    //修改
    @ApiOperation(value = "更新")
    @ApiImplicitParam(name = "user",value = "用户的信息",required = true,dataType = "User",paramType = "body")
    @PutMapping("")
    public void updateUser(@ApiParam(value = "用户或用户各个属性") @RequestBody User user) {
        userService.upDate1(user);
    }
    //部分更新
    @ApiOperation(value = "部分更新",notes = "实行部分更新")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "User",paramType = "query")
    @PatchMapping("")
    public void updateUser1(@ApiParam(value = "用户或用户各个属性") User user) {
        userService.upDate1(user);
    }
    @ApiOperation(value = "添加",notes = "添加用户")
    public String addUser(User user ){  //使用@RequestBody注解 swaager输入一行一行的参数的格式会消失
        userService.addUser(user);
        return "success";
    }
    //传用户名密码直接判断
    @ApiOperation(value = "登录",notes="注意事项")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "name",value = "用户名",required = true,paramType = "query"),
            @ApiImplicitParam(dataType = "Integer",name = "password",value = "密码",required = true,paramType = "query")
    })
    @PostMapping("/login")
    public List<User> login5( @RequestParam String name,@RequestParam Integer password){
        List<User> book_list = userService.login5(name,password);
        System.out.println(book_list);
        if (book_list !=null){
            System.out.println("用户名："+name+"password："+password+"登录成功");
        }else{
            System.out.println("登录失败");
        }
        return book_list;
    }
}
<file_sep>package com.taifan;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//@ComponentScan//启动类 所在的包的路径
@MapperScan("com.taifan.mapper")//springBoot中集成mybates可以让别的类进行引用
@EnableAsync//注解可以异步执行，就是开启多线程的意思在方法上写@Async
@SpringBootApplication(scanBasePackages = "com.taifan")//：包含@EnableAutoConfiguration、@ComponentScan、@SpringBootConfiguration申明让springboot自动给程序必要的配置
@EnableWebMvc//用于启动springMVC特性
@EnableSwagger2
public class ZhuLei {
    public static void main(String[] args) {
        SpringApplication.run(ZhuLei.class,args);
    }
}
<file_sep>package com.taifan1.domain;

public class Us {
    private Integer id;
    private Integer menu_id;
    private Integer user_id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMenu_id() {
        return menu_id;
    }

    public void setMenu_id(Integer menu_id) {
        this.menu_id = menu_id;
    }

    public Integer getUser_id() {
        return user_id;
    }

    public void setUser_id(Integer user_id) {
        this.user_id = user_id;
    }

    @Override
    public String toString() {
        return "Us{" +
                "id=" + id +
                ", menu_id=" + menu_id +
                ", user_id=" + user_id +
                '}';
    }
}
<file_sep>package com.education.service;

import com.education.domain.Menu;
import com.education.domain.MenuAfter;
import com.education.domain.Resources;
import com.education.mapper.MenuMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

@Service
public class MenuServiceimpl implements MenuService{

    @Resource
    private MenuMapper menuMapper;

    Menu menu = new Menu();

    //查询所有菜单
    @Override
    public int getMenuAll() {
        return menuMapper.getMenuAll();
    }

    //查询根节点
    @Override
    public Menu getMenu2() {
        return menuMapper.getMenu2();
    }

    //根据id获取根节点对象
    @Override
    public Menu getMenu1(String id) {
        return menuMapper.getMenu1(id);
    }

    //查询id下的所有子节点
    @Override
    public List<Menu> getMenu(String id) {
        return menuMapper.getMenu(id);
    }

    //添加菜单
    @Override
    public void addMenu(MenuAfter menuAfter) {
        Calendar calendar = Calendar.getInstance(TimeZone.getDefault());//获取当前时间
        menu.setCreatedon(calendar.getTime());//把当前时间给menu对象里面的setCreatedon
        BeanUtils.copyProperties(menuAfter,menu);//把menuAfter里的数据赋给menu对象
        menuMapper.addMenu(menu);//把menu对象传过去
    }

    //修改菜单
    @Override
    public void upDateMenu(MenuAfter menuAfter) {
        Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
        System.out.println("获取的当前时间"+calendar);
        menu.setCreatedon(calendar.getTime());
        menu.setUpdatedon(calendar.getTime());
        BeanUtils.copyProperties(menuAfter,menu);
        menuMapper.upDateMenu(menu);
    }

    //删除菜单
    @Override
    public void deleteMenu(String id) {
        menuMapper.deleteMenu(id);
    }

    //给菜单赋予资源
    //先查询是否已经赋值过
    @Override
    public int selectMenuByIdResourcesById(String id, String resourcesId) {
        return menuMapper.selectMenuByIdResourcesById(id,resourcesId);
    }
    //赋资源
    @Override
    public int addMenuResources(String id, String resourcesId) {
        return menuMapper.addMenuResources(id,resourcesId);
    }

    //根据菜单id查询对应的资源
    @Override
    public List<Resources> getMenuById(String id) {
        return menuMapper.getMenuById(id);
    }


}
<file_sep>
buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group 'education'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-web')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:2.0.0.RELEASE'//是指依赖的Jar包不会被加到War包里面
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile group: 'com.alibaba', name: 'druid', version: '1.1.12'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.53'
    compile group: 'org.scala-lang', name: 'scala-library', version: '2.13.0-M5-6e0cba7'
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
    compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.2.5'
    
    //转excel用到的依赖
/*    compile group: 'org.apache.poi', name: 'poi', version: '3.17'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
    compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
    compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
    compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'*/
    //公用方法导入导出依赖
    compile group: 'cn.afterturn', name: 'easypoi-base', version: '3.0.3'
    compile group: 'cn.afterturn', name: 'easypoi-web', version: '3.0.3'
    compile group: 'cn.afterturn', name: 'easypoi-annotation', version: '3.0.3'
//自动更新项目
  //  compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.4.RELEASE'




}
<file_sep>/*
Navicat MySQL Data Transfer

Source Server         : xt1
Source Server Version : 50716
Source Host           : localhost:3306
Source Database       : education

Target Server Type    : MYSQL
Target Server Version : 50716
File Encoding         : 65001

Date: 2019-01-09 15:52:55
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `menu`
-- ----------------------------
DROP TABLE IF EXISTS `menu`;
CREATE TABLE `menu` (
  `id` char(36) NOT NULL,
  `code` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `icon` varchar(50) DEFAULT NULL,
  `url` varchar(50) DEFAULT NULL,
  `parent_id` char(36) DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL,
  `order` int(10) DEFAULT NULL,
  `status` varchar(50) DEFAULT NULL,
  `description` text,
  `created_by` varchar(50) DEFAULT NULL,
  `created_on` datetime DEFAULT NULL,
  `updated_by` varchar(50) DEFAULT NULL,
  `updated_on` datetime DEFAULT NULL,
  `is_leaf` varchar(50) DEFAULT NULL,
  `default_menus` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of menu
-- ----------------------------
INSERT INTO `menu` VALUES ('7f34daee13e011e9b7e7fc459644994c', 'string', '仓库管理', 'string', 'string', 'string', 'string', '0', 'string', 'string', 'string', '2019-01-09 15:30:54', 'string', null, 'string', 'string');
INSERT INTO `menu` VALUES ('9db4225613e111e9b7e7fc459644994c', 'string', '教学过程', 'string', 'string', '7f34daee13e011e9b7e7fc459644994c', 'string', '0', 'string', 'string', 'string', '2019-01-09 15:38:55', 'string', null, 'string', 'string');

-- ----------------------------
-- Table structure for `menu_resources`
-- ----------------------------
DROP TABLE IF EXISTS `menu_resources`;
CREATE TABLE `menu_resources` (
  `id` char(36) NOT NULL,
  `menu1_id` char(36) DEFAULT NULL,
  `resources_id` char(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `menu1_id` (`menu1_id`),
  KEY `resources_id` (`resources_id`),
  CONSTRAINT `menu1_id` FOREIGN KEY (`menu1_id`) REFERENCES `menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `resources_id` FOREIGN KEY (`resources_id`) REFERENCES `resources` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of menu_resources
-- ----------------------------
INSERT INTO `menu_resources` VALUES ('5c207f4a13e111e9b7e7fc459644994c', '7f34daee13e011e9b7e7fc459644994c', '4632d7d913e111e9b7e7fc459644994c');

-- ----------------------------
-- Table structure for `resources`
-- ----------------------------
DROP TABLE IF EXISTS `resources`;
CREATE TABLE `resources` (
  `id` char(36) NOT NULL,
  `code` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `description` text,
  `created_by` varchar(50) DEFAULT NULL,
  `created_on` datetime DEFAULT NULL,
  `updated_by` varchar(50) DEFAULT NULL,
  `updated_on` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of resources
-- ----------------------------
INSERT INTO `resources` VALUES ('4632d7d913e111e9b7e7fc459644994c', 'string', '添加', 'string', 'string', '2019-01-09 15:36:28', 'string', null);

-- ----------------------------
-- Table structure for `role`
-- ----------------------------
DROP TABLE IF EXISTS `role`;
CREATE TABLE `role` (
  `id` char(36) NOT NULL,
  `name` varchar(50) DEFAULT NULL,
  `code` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of role
-- ----------------------------
INSERT INTO `role` VALUES ('0518eef513de11e9b7e7fc459644994c', '管理员', '159');
INSERT INTO `role` VALUES ('42b923d613d411e9b7e7fc459644994c', 'ppp', '111');

-- ----------------------------
-- Table structure for `role_menu`
-- ----------------------------
DROP TABLE IF EXISTS `role_menu`;
CREATE TABLE `role_menu` (
  `id` char(36) NOT NULL,
  `role1_id` char(36) DEFAULT NULL,
  `menu_id` char(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `role1_id` (`role1_id`),
  KEY `menu_id` (`menu_id`),
  CONSTRAINT `menu_id` FOREIGN KEY (`menu_id`) REFERENCES `menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `role1_id` FOREIGN KEY (`role1_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of role_menu
-- ----------------------------
INSERT INTO `role_menu` VALUES ('9af1e2c413e011e9b7e7fc459644994c', '0518eef513de11e9b7e7fc459644994c', '<PASSWORD>');

-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` char(36) NOT NULL,
  `name` varchar(50) DEFAULT NULL,
  `password` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('2<PASSWORD>', '张三', '456');

-- ----------------------------
-- Table structure for `user_role`
-- ----------------------------
DROP TABLE IF EXISTS `user_role`;
CREATE TABLE `user_role` (
  `id` char(36) NOT NULL,
  `user_id` char(36) DEFAULT NULL,
  `role_id` char(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `role_id` (`role_id`),
  CONSTRAINT `role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_role
-- ----------------------------
INSERT INTO `user_role` VALUES ('<KEY>', '2<PASSWORD>bc13de11e9b7e7fc459644994c', '<PASSWORD>');
<file_sep>/*
Navicat MySQL Data Transfer

Source Server         : xt1
Source Server Version : 50716
Source Host           : localhost:3306
Source Database       : taifan

Target Server Type    : MYSQL
Target Server Version : 50716
File Encoding         : 65001

Date: 2018-12-29 15:35:18
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `password` int(50) DEFAULT NULL,
  `created_by` varchar(50) DEFAULT NULL,
  `user_type` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '张三', '123', '张三', 'ooo');
INSERT INTO `user` VALUES ('2', '李四', '123', '李四', 'ppp');
INSERT INTO `user` VALUES ('3', '王五', '555', '王五', 'aaa');
INSERT INTO `user` VALUES ('4', '赵六', '632', '赵六', 'qqq');
