百度过了,都说是 xml 文件的编码问题,但是各种文本编辑器都试过转为无 BOM 的UTF8编码,都照样报这个错。最后,在CentOS下,用Java程序生成的 xml 再下载后复制到对应目录下,错误一模一样。
真不知道咋办了!
xml 内容:
<?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.hynn.ems.models.db.mapper.TestMapper"> <resultMap id="testResult" type="com.hynn.ems.models.db.Test"> <result column="Id" jdbcType="varchar" property="id" /> <result column="Creator_Id" jdbcType="bigint" property="creatorId" /> <result column="Create_Time" jdbcType="datetime" property="createTime" /> <result column="Updater_Id" jdbcType="bigint" property="updaterId" /> <result column="Update_Time" jdbcType="datetime" property="updateTime" /> <result column="Name" jdbcType="varchar" property="name" /> </resultMap> <select id="findById" resultMap="testResult"> Select * From Test Where Id = #{id} </select> </mapper>
在 CentOS 下生成 xml 的代码:
package test; import java.io.*; public class WriteFile { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\r\n"); sb.append("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">").append("\r\n"); sb.append("<mapper namespace=\"com.hynn.ems.models.db.mapper.TestMapper\">").append("\r\n"); sb.append(" <resultMap id=\"testResult\" type=\"com.hynn.ems.models.db.Test\">").append("\r\n"); sb.append(" <result column=\"Id\" jdbcType=\"varchar\" property=\"id\" />").append("\r\n"); sb.append(" <result column=\"Creator_Id\" jdbcType=\"bigint\" property=\"creatorId\" />").append("\r\n"); sb.append(" <result column=\"Create_Time\" jdbcType=\"datetime\" property=\"createTime\" />").append("\r\n"); sb.append(" <result column=\"Updater_Id\" jdbcType=\"bigint\" property=\"updaterId\" />").append("\r\n"); sb.append(" <result column=\"Update_Time\" jdbcType=\"datetime\" property=\"updateTime\" />").append("\r\n"); sb.append(" <result column=\"Name\" jdbcType=\"varchar\" property=\"name\" />").append("\r\n"); sb.append(" </resultMap>").append("\r\n"); sb.append(" <select id=\"findById\" resultMap=\"testResult\">").append("\r\n"); sb.append(" Select * From Test Where Id = #{id}").append("\r\n"); sb.append(" </select>").append("\r\n"); sb.append("</mapper>").append("\r\n"); String content = sb.toString(); try(FileOutputStream fos = new FileOutputStream("D:\\UserMapping.xml")){ byte[] data = content.getBytes("UTF8"); fos.write(data, 0, data.length); }catch(Exception ex) { ex.printStackTrace(); } } }
<?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">
<!--Mybatis-Plus——使用 Wrapper 自定义SQL: https://www.bilibili.com/read/cv14498117-->
<mapper namespace="com.zhike.blogdao.mapper.ArticleMapper">
<select id="selectArticleByUserId" resultType="com.zhike.blogpojo.DO.Article">
SELECT a.* FROM `article` a
INNER JOIN `article_type` b
ON b.`Id`=a.`ArticleTypeId`
WHERE `UserId`=#{userId}
</select>
</mapper>
自己解决了
原来是 application.yml 配置不对,原来是: