参考博客spring
<dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.2</version> </dependency>
通用mapper是在springboot集成了Mybatis的基础上进行使用的数据库
package com.boss.hr.train.fishkkmybatis.basedao; import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.MySqlMapper; /** * * 公用Mapper接口 *@author fishkk *@version 1.0.0 *@since * * 修改人信息 *@author *@version *@since * */ public interface BaseDao<T> extends Mapper<T>,MySqlMapper<T> { }
以后- 全部继承BaseDao的接口都最有通用mapper的功能springboot
##通用mapper配置 mapper: ##实体类所在的包 mappers: com.boss.hr.train.fishkkmybatis.basedao.BaseDao identity: MYSQL
可是通用mapper值适合单表操做,若是涉及到夺标操做仍是不能避免使用Mybatis来写SQL语句mybatis
package com.xyz.mapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import tk.mybatis.spring.annotation.MapperScan; @SpringBootApplication @MapperScan("com.xyz.mapper.dao")//注意MapperScan要导tk的包,否则会报NoSuchMethodException public class MapperApplication { public static void main(String[] args) { SpringApplication.run(MapperApplication.class, args); } }
最后一步,为添加起步依赖注释app
mybatis的逆向工程中会生成实例及实例对应的example,example用于添加条件,至关where后面的部分
Example为咱们建立的实例 Example.createCriteria()为咱们建立了条件容器,而后将咱们的筛选条件一一添加到里面,最后用这个实例去查询
Example的具体使用
写的很详细,我就不当一个搬运工了。框架