SpringBoot整合Mybatis完整详细版 入门资料

入门资料 记录

controller:接收请求

entity:存放 Java Bean 类

mapper:关联 SQL 语句

service:处理业务逻辑

处理流程:controller --> service --> mapper (entity的bean类用来存放和获取数据)

在项目中配置多套环境的配置方法。
因为现在一个项目有好多环境,开发环境,测试环境,准生产环境,生产环境,每个环境的参数不同,所以我们就可以把每个环境的参数配置到yml文件中,这样在想用哪个环境的时候只需要在主配置文件中将用的配置文件写上就行如application.yml

笔记:在Spring Boot中多环境配置文件名需要满足application-{profile}.yml的格式,其中{profile}对应你的环境标识,比如:

application-dev.yml:开发环境
application-test.yml:测试环境
application-prod.yml:生产环境
至于哪个具体的配置文件会被加载,需要在application.yml文件中通过spring.profiles.active属性来设置,其值对应{profile}值。

还有配置文件中最好不要有中文注释,会报错。

resources下创建mapping文件夹,用于写sql语句,也可以用注解的方式直接写在mapper文件里。

 Pom文件添加依赖

在pom文件添加mybatis-plus框架需要的相关依赖。

 

配置数据库连接驱动,日志级别。配置如下图。

mybatis.typeAliasesPackage 配置为 org.spring.springboot.domain,指向实体类包路径。mybatis.mapperLocations 配置为 classpath 路径下 mapper 包下,* 代表会扫描所有 xml 文件。

mybatis 其他配置相关详解如下:

mybatis.config = mybatis 配置文件名称

mybatis.mapperLocations = mapper xml 文件地址

mybatis.typeAliasesPackage = 实体类包路径

mybatis.typeHandlersPackage = type handlers 处理器包路径

mybatis.check-config-location = 检查 mybatis 配置是否存在,一般命名为 mybatis-config.xml

mybatis.executorType = 执行模式。默认是 SIMPLE

org.spring.springboot.controller – Controller 层
org.spring.springboot.dao – 数据操作层 DAO
org.spring.springboot.domain – 实体类
org.spring.springboot.service – 业务逻辑层
Application – 应用启动类
application.properties – 应用配置文件,应用启动会自动读取配置

REF

GOOD 入门资料

https://zhuanlan.zhihu.com/p/153622921

https://zhuanlan.zhihu.com/p/154527314

https://www.cnblogs.com/jiuhaoyun/p/10102263.html

https://blog.csdn.net/iku5200/article/details/82856621

https://www.cnblogs.com/peterxiao/p/7779188.html

https://www.jianshu.com/p/541874714907

https://blog.csdn.net/u012702547/article/details/88643598

https://www.cnblogs.com/wangshen31/p/8744157.html

https://www.cnblogs.com/lhboke/p/13253153.html

 https://cloud.tencent.com/developer/news/583238

https://github.com/wjup/springBoot_Mybatis/tree/master/Springboot_Mybatis

http://blog.wjup.top/2019/09/30/%E4%B8%80%E5%B0%8F%E6%97%B6%E5%BF%AB%E9%80%9F%E6%92%B8%E5%87%BA%E7%9F%AD%E7%BD%91%E5%9D%80%E7%94%9F%E6%88%90%E9%A1%B9%E7%9B%AE/

https://www.cnblogs.com/alanturingson/p/12931440.html

https://www.cnblogs.com/youngdeng/p/12858077.html

利用 Mybatis-generator自动生成代码 http://www.cnblogs.com/yjmyzz/p/4210554.html
Mybatis 通用 Mapper3 https://github.com/abel533/Mapper
Mybatis 分页插件 PageHelper https://github.com/pagehelper/Mybatis-PageHelper
最后,推荐阅读:《 Spring Boot 之 HelloWorld 详解
 
 
原文地址:https://www.cnblogs.com/emanlee/p/14539823.html