跳过测试类打包:
需求说明:meven执行打包命令时,默认条件下,会执行测试类中的方法,可能某些测试方法由于种种原因,执行报错,则install的操作执行失败
<properties>
<!--指定JDK版本-->
<java.version>1.8</java.version>
<!--跳过测试类打包-->
<skipTests>true</skipTests>
</properties>
1.序列化作用
pojo类直线序列化接口:保证对象网络传输的有效性
2.YML文件
spring:
datasource:
#如果使用高版本驱动 则添加cj
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
#Spring整合Mybatis
mybatis:
#定义别名包
type-aliases-package: com.jt.pojo
#导入映射文件
mapper-locations: classpath:/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
1.serverTimezone=GMT%2B8& 时区
2.useUnicode=true& 是否使用unicode编码
3.characterEncoding=utf8& 字符集使用utf-8
4.autoReconnect=true& 自动重连
5.allowMultiQueries=true 运行批量操作
3.XML文件
关键词:namespace(mapper接口) id(接口方法名) resultType resultMap(类型名)
SQL语句不加;加后可能报错
4.主启动类
@Mapper 将接口交给spring管理,spring创建对象;如果有多个接口,则应表示多次
优化:可以采用@MapperScan("XXXX接口的包路径")载重启动类
5.关于整合的BUG
第一:关于XML文件位置说明
xml文件不建议在根目录下,可能会报错;
如果报错显示找不到文件,可能是yml中 导入映射文件存在问题:
错误: mapper-locations: classpath:*.xml
纠正: mapper-locations: classpath:/mappers/*.xml或 mapper-locations: classpath*:/*.xml
错误: mapper-locations: classpath:/aaa.bbb.ccc/*.xml
纠正: mapper-locations: classpath:/aaa/bbb/ccc/*.xml
第二:IDEA关于Mapper注入
连接数据库接口必须有对象,通过包路径的扫描,在运行期间实现对象的创建,实现了数据的绑定,所以测试类中接口对象下红线报错...
解决一: