MyBatis框架常见报错解决方案
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="url" value="jdbc:mysql://localhost:3306/classification?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=round"/>
<property name="driver" value="com.mysql.jdbc.Driver"/>
</properties>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="poolMaximumActiveConnections" value="10"/>
<property name="poolMaximumIdleConnections" value="3"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="classification/conf/textclassification.xml"/>
</mappers>
</configuration>
配置mybatis.xml报错:“The reference to entity "zeroDateTimeBehavior" must end with the ';' delimiter.”
这里“zeroDateTimeBehavior”是配置url属性的最后一个参数,因为xml文件识别不了“&”符号,因此需要在其后面添加“amp;”
解决方法:在每个“&”附号后面添加“amp;”
类似的,在xml文件中有以下几类字符要进行转义替换:
< |
< |
小于号 |
> |
> |
大于号 |
& |
& |
和 |
' |
' |
单引号 |
" |
" |
双引号 |