zoukankan      html  css  js  c++  java
  • 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中

  • 相关阅读:
    Remove Element
    Binary Tree Inorder Traversal
    Symmetric Tree
    Roman to Integer
    Search Insert Position
    Reverse Integer
    Pascal's Triangle
    Merge Sorted Array
    Same Tree
    Visual Studio Code 做PHP开发
  • 原文地址:https://www.cnblogs.com/keyi/p/8534905.html
Copyright © 2011-2022 走看看