SpringBoot整合Mybatis -- 配置文件版

1、项目资源结构目录

SpringBoot整合Mybatis -- 配置文件版_第1张图片

2、创建mybatis-config.xml


    
    
        
    

    
        
    

    
    
        
    

3、创建EmployeeMapper.xml


     

    
        insert into employee(lastName, email, gender, d_id) values(#{lastName}, #{email}, #{gender}, #{dId})
    

4、application.yml文件中配置,指定全局配置文件的位置

mybatis:
  config-location: classpath:mybatis/mybatis-config.xml
  mapper-locations: classpath:mybatis/mapper/*.xml

5、编写controller

  @ResponseBody
    @GetMapping("/emp/{id}")
    public Employee findEmpById(@PathVariable("id") Integer id){ //@PathVariable接收请求路径中占位符的值
        Employee employee = employeeMapper.queryById(id);
        return employee;
    }

 

你可能感兴趣的:(SpringBoot框架学习,mybatis,xml,spring,spring,boot,数据库)