做分页查询时,查询符合条件的总记录数报错:
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'nameText' in 'class java.lang.String'
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'nameText' in 'class java.lang.String'
at
mapper.xml的写法为:
<select id="getUserCount" resultMap="ResultMapWithBLOBs">
select count(*)
from user
<if test="nameText != null">
where name like CONCAT(CONCAT('%', #{nameText}), '%')
</if>
</select>
原因:接口中返回值为int,所以这里的resultMap不可以是实体类,而应该是Integer,修改为:
<select id="getUserCount" parameterType="string" resultType="int">
select count(*)
from user
<if test="nameText != null">
where name like CONCAT(CONCAT('%', #{nameText}), '%')
</if>
</select>
int getUserCount(@Param("nameText") String nameText);