springboot整合mybatis
1.配置文件版
1.配置数据源
spring.datasource.username=root spring.datasource.password=fuck spring.datasource.url=jdbc:mysql://localhost:3306/mybatis spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
2.mapper文件的位置
mybatis.mapper-locations=classpath:/mappers/*.xml
3.指定起别名的类
mybatis.type-aliases-package=com.entities
4.在主程序中扫描Dao接口
@SpringBootApplication @MapperScan("com.mapper") public class HelloWorldMainApplication { public static void main(String[] args) { SpringApplication.run(HelloWorldMainApplication.class,args); } }
2.注解版
1.配置数据源
spring.datasource.username=root spring.datasource.password=fuck spring.datasource.url=jdbc:mysql://localhost:3306/mybatis spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
2.指定起别名的类
mybatis.type-aliases-package=com.entities
3.在主程序中扫描Dao接口
@SpringBootApplication @MapperScan("com.mapper") public class HelloWorldMainApplication { public static void main(String[] args) { SpringApplication.run(HelloWorldMainApplication.class,args); } }
4.在Dao接口上编写sql语句
@Select("select * from person") public List<Person> getAll();