mybatis官网:https://github.com/mybatis1.配置方式
①找到starter场景启动器,pom.xml中找到依赖,注意不要快照版,要稳定版。
org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.4
在自己的项目pom.xml中导入上述依赖。
②在yaml配置文件中配置mybatis的全局配置:
#配置mybatis规则
mybatis:
# config-location: classpath:mybatis/mybatis-config.xml #全局配置文件
mapper-locations: classpath:mybatis/mapper
@Select("select * from city where id = #{id}")
City getCityById(Long id);
}
- 在mapper接口的方法上标注要进行的的SQL注解,编写SQL语句。
采用纯注解的方式,不需要在编写SQL映射配置文件。
当SQL查询比较复杂,纯注解的方式不满足需要的时候,可以采用混合方式,同时采用配置方式和注解方式。



