问题描述
今天在测试mybatis一个小项目时发现一个有趣的现象
就是我的xml配置文件(对应的相应Dao接口)中在执行时报出了字符集的问题
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.guo.dao.UserMapper">
<resultMap id="UserMap" type="com.guo.pojo.User">
</resultMap>
<select id="getUserList" resultType="com.guo.pojo.User">
select * from mybatis.user
</select>
<select id="getUserbyId" resultType="com.guo.pojo.User">
select * from mybatis.user where id= #{id}
</select>
<select id="getUserLike" resultType="user">
select * from mybatis.user where name like "%"#{value}"%"
</select>
<select id="getUserByLimit" parameterType="map" resultType="User">
select * from mybatis.user limit #{startIndex},#{pageSize}
</select>
<!-- 分页2-->
<select id="getUserByRowBounds" resultMap="UserMap">
select * from mybatis.user
</select>
<insert id="addUser" parameterType="com.guo.pojo.User">
insert into mybatis.user(id, name, pwd) values(#{id},#{name},#{pwd});
</insert>
<update id="updateUser" parameterType="com.guo.pojo.User">
update mybatis.user set name=#{name},pwd=#{pwd} where id=#{id}
</update>
<delete id="deleteUserById" parameterType="int">
delete from mybatis.user where id=#{id}
</delete>
</mapper>
解决方案
在翻阅网上资料后发现只要删除xml文件中的中文注释就可以解决这个Error
或者将xml文件第一行的字符集从uft-8改为uft8也可!
ok执行成功!