mybatis :xml文件中传入参数和if标签结合使用时要点


org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named 'source' in 'class java.lang.String' at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) at com.sun.proxy.$Proxy20.selectOne(Unknown Source)

  一、原始

DAO接口方法:
public int getSjNumbySource(String source);



mybatis的XML配置文件

<select id="getSjNumbySource" resultType="java.lang.Integer" parameterType="java.lang.String"> SELECT COUNT(*) FROM t_apb_res_info WHERE RES_KIND='FL3' AND RES_TYPE='LX7' <if test="source != null and source !=''"> AND RES_SOURCE=#{source,jdbcType=VARCHAR} </if> </select>

mybatis中如果用了if那么传进来的参数不能直接单独传入,要封装到map或vo(对象)中

如果是直接传单个参数会报上面的错。

 

解决方法:

public int getSjNumbySource(Map map);

  然后在controller层将数据source放进map中

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM