What to pay attention to when using the passed parameters and if in the mybatis xml file

 

If if is used in mybatis, the parameters passed in cannot be passed in directly. It needs to be encapsulated in map or bo and passed in, or go to if

 

 

Things to pay attention to when using the passed parameters and if in the mybatis xml file:

 

 

Here, int is passed directly, but if is used again, so it is wrong

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'customerKey' in 'class java.lang.Integer'

<select id="getYJSL" parameterType="Integer" resultType="int">

   SELECT count(*) yjsl    

   FROM tb_con_obj A, TB_CON_ORD B 

   WHERE A.CONOBJ_KEY = B.CONOBJ_KEY  

   AND A.IS_CONFERPRICE = 'Y'

   AND B.ORDER_STATUS = 'A' 

   AND A.CONOBJ_STATUS <![CDATA[<>]]> 'E'

   <if test="customerKey !=null and customerKey!='' ">

   AND (B.CUSTOMER_KEY = #{customerKey} or a.customer_key = #{customerKey})

   </if>

  </select>

 

====

 

  When using the SpringMVC+Mybatis framework to write a project, this error occurred at the sql statement in the mapper

<if test="agoTime != null">

and updateTime > #{agoTime}

</if>

The reason is:

If the #{attribute} in the and statement is written in the if statement, mybatis will go to the object to get the value from its get method, and I passed the value directly before, and did not encapsulate the object.

 

Solution:

Encapsulate the property into an object and set its get method

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326412594&siteId=291194637