mybatis-config.xml文件配置问题

Question one:mybatis配置文件标签组成及排序


Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 99; columnNumber: 17; 元素类型为 "configuration" 的内容必须匹配 "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)"。

查看mybatis官方文档

https://mybatis.org/mybatis-3/zh/configuration.html

https://mybatis.org/mybatis-3/configuration.html

mybatis要按照标签的顺序和规整写,不然可能就会报这类错误

我产生错误的原因是因为我写了两个properties标签,

 

修改之后:

如果改变标签的顺序也同样会出现此类错误

 

Question two:重复注册


Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.github.pagehelper.PageInterceptor'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.github.pagehelper.PageInterceptor

Caused by: org.apache.ibatis.binding.BindingException: Type interface com.sunny.min.dao.TestExcMapper is already known to the MapperRegistry

重复注册

Question three:未导入jar包


Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver

原因:未导入mysql-connector-java的jar包

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

 

Question four:版本问题


Caused by: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

修改对应的版本:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.47</version>
</dependency>

 

Question five:字段名对应


明明sql查询有数据,为什么返回的list是All elements are null

原因:

在使用mybatis返回值的时候,返回值类型为List<Map<String,Object>> ,由于ArrayList允许null存在,所以返回的list无法用非空来判断,他的长度为1 ,但是在取值的的时候会报空指针异常

解决方法:将sql语句返回的字段使用驼峰命名法命名,

实际上产生All elements are null的原因:

解决办法:在mybatis-config.xml文件中添加,默认是false

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值