MyBatis映射异常:
上层请求的参数与实体类属性不对应,这里传入了一个给stutus传入了一个List,而实体类中是String类型,类型不匹配。
异常信息:
ERROR c.k.f.w.e.GlobalExceptionHandler - [handleRuntimeException,69] - 请求地址'/system/XXX',发生未知异常.
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'list' in 'class com.ktg.quartz.domain.XXXX'
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy107.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
at com.sun.proxy.$Proxy168.selectSysTodoList(Unknown Source)
at com.ktg.quartz.service.impl.SysTodoServiceImpl.selectSysTodoList(SysTodoServiceImpl.java:44)
at com.ktg.quartz.controller.SysTodoController.list(SysTodoController.java:48)
at com.ktg.quartz.controller.SysTodoController$$FastClassBySpringCGLIB$$72e747f3.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783)
我是想在sql中传入实体类作为查询条件,同时传入一个List带多个状态通过foreach一起查询出来
<select id="selectSysTodoList" parameterType="SysTodo" resultMap="SysTodoResult">
<include refid="selectSysTodoVo"/>
<where>
<if test="todoTitle != null and todoTitle != ''"> and todo_title = #{todoTitle}</if>
<if test="todoType != null and todoType != ''"> and todo_type = #{todoType}</if>
<if test="todoContent != null and todoContent != ''"> and todo_content = #{todoContent}</if>
<if test="todoObject != null "> and todo_object = #{todoObject}</if>
<if test="status != null and status != ''">
and status in
<foreach item="status" collection="list" open="(" separator="," close=")">
#{status}
</foreach>
</if>
<if test="expire != null "> and expire = #{expire}</if>
<if test="workshopId != null "> and workshop_id = #{workshopId}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
</where>
</select>
解决起来比较简单,上层直接传一个String过来就行 this.params.status = “0,1,3”,sql这边去掉 标签,不过不能直接改成and status in #{status},会出现格式问题,在msqyl中使用FIND_IN_SET(status, #{status})就OK!
<if test="todoObject != null "> and todo_object = #{todoObject}</if>
<if test="status != null and status != ''"> and FIND_IN_SET(status,#{status})</if>
<if test="expire != null "> and expire = #{expire}</if>
版权声明:本文为liao_sp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。