在使用mybatis时遇到的问题。分享给大家
R
ResultMapWithBLOB是我自定义的一个resultmap。代码如下
<resultMap id="ResultMapWithBLOB" type="model.Blog" > <constructor > <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" /> <arg column="title" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="describle" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="writer" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="context" jdbcType="LONGVARCHAR" javaType="java.lang.String" /> </constructor> </resultMap> <sql id="Base_Column_List" > id, title, describle, writer </sql> <sql id="Blob_Column_List" > context </sql> <select id="selectByPrimaryKey" resultType="ResultMapWithBLOB" parameterType="java.lang.String" > select <include refid="Base_Column_List" /> , <include refid="Blob_Column_List" /> from blog where writer = #{writer,jdbcType=VARCHAR} </select>
再把单元测试的代码贴出来
public void showpersonblog()throws Exception{ List<Blog> b=blogService.showAllBlogPerson("1"); for (Blog c:b ) { System.out.println(c.getId()); System.out.println(c.getContext()); System.out.println(c.getDescrible()); System.out.println(c.getTitle()); System.out.println(c.getWriter()); } }
问题原因:MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接
表示返回类型的,而resultMap则是对外部ResultMap的引用,但是resultType跟resultMap不能同时存在。
解决方法:将resulttype改为resultmap
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOB" parameterType="java.lang.String" > select <include refid="Base_Column_List" /> , <include refid="Blob_Column_List" /> from blog where writer = #{writer,jdbcType=VARCHAR} </select>
时间: 2024-10-08 20:41:29