##springboot整合mybaitis
添加依赖:pom.xml
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-configuration-processor true org.springframework.boot spring-boot-starter-thymeleaf mysql mysql-connector-java org.mybatis.spring.boot mybatis-spring-boot-starter 2.2.2 com.alibaba fastjson 1.2.78
配置文件:application.prperties(yml)
#端口
server.port=8080
#项目根路径
server.servlet.context-path=/bootDemo
#student.age=13
#logging.level.cn.kgc.bootdemo=trace
#配置日志文件,我的是logback.xml,也可以配置其他日志文件
logging.config=classpath:logback.xml
#关闭缓存
spring.thymeleaf.cache=false
#配置数据库
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/
spring.datasource.name=root
spring.datasource.password=root
#配置mybatis
#配置映射文件路径
mybatis.mapper-locations=classpath:mappers
@Override
public List getPetList() {
return petDao.getPetList();
}
}
Controller层:
@RestController
public class PetController {
//最好是Resource
@Resource
private PetService petService;
petTypeService;
@RequestMapping("/petlist")
public String getPetList(@RequestParam(required = false)String breed){
System.out.println("品种"+breed);
if (breed==null||breed.equals("0")){
return JSON.toJSONString(petService.getPetList());}
else {
return JSON.toJSONString(petService.getPetListByTypeName(breed));
}
}
}



