SpringBoot集成Mybatis

1.导入依赖mysqlmysql-connector-javaorg.mybatis.spring.bootmybatis-spring-boot-starter2.0.0.....加插件src/main/java**/*.xmlorg.mybatis.generatormybatis-generator-maven-plugin1.3.6GeneratorMapper.xmltruetrue2.创建数据库 , 用逆向工程生成相应的mapper层和model实体层3.在Controller层中@Controllerpublic class StudentController {@Autowiredprivate StudentService studentService;@RequestMapping(value = "http://kandian.youth.cn/student")public @ResponseBody Student queryStudentById(Integer id) {//调用业务层的方法Student student = studentService.queryStudentById(id);return student;}}在service层中创建StudentService
public interface StudentService {/*** 根据学生ID查询详情* @param id* @return*/Student queryStudentById(Integer id);}创建实现类StudentServiceImpl
@Servicepublic class StudentServiceImpl implements StudentService {@Autowiredprivate StudentMapper studentMapper;@Overridepublic Student queryStudentById(Integer id) {return studentMapper.selectByPrimaryKey(id);}}4.在application.properties中#设置连接数据的信息spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://192.168.154.128:3306/springboot?useUnicode=true --tt-darkmode-bgcolor: #C0BEB8;">5.在SpringBootApplication启动类中加入@MapperScan注解@SpringBootApplication//开启spring配置@MapperScan("com.bjpowernode.springboot.mapper") //开启扫描Mapper接口的包以及子目录public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}}结尾【SpringBoot集成Mybatis】本文到这里就结束了 , 感谢看到最后的朋友 , 都看到最后了 , 点个赞再走啊 , 如有不对之处还请多多指正 。