Mybatis single parameter if judgment (for exception: There is no getter for property ..)

Source: Internet
Author: User

Mybatis single parameter if judgment (for exception: There is no getter for property ..)

We all know that mybatis can be directly used for parameter determination. As shown in the following figure:

1. General Code

 

 
      update t_test_l    
        
   
            trnsct_way_id = #{trnsctWayId,jdbcType=TINYINT},      
         
   
            lang_id = #{langId,jdbcType=INTEGER},      
       
      where trnsct_way_l_id = #{trnsctWayLId,jdbcType=INTEGER}  
 

 

However, there is a difference between single parameter and multi-parameter judgment. When our input parameter is an entity object or map, it is no problem to use the if parameter to judge.

But when our input parameter is java. lang. Integer or java. lang. String, you need to pay attention to some things.

The specific code is as follows (let's look at the code and show the error code first ):

2. Error Code

<select id="getTrnsctListByLangId" parameterType="java.lang.Integer" resultType="java.lang.Integer">      select        trnsct_id      from  t_trnsct_way_l where       <if test="langId != null" >         and lang_id = #{langId}      </if>    </select>  
 

The above code has some problems. The first input parameter is java. lang. integer, instead of the map or object input parameter method. For this type of single input parameter and then determined by if, mybatis has its own built-in object,

 

If you write the Object Name of your input parameter in the if statement, an exception occurs: Internal error: nested exception is org. apache. ibatis. reflection. reflectionException: There is no getter for property named 'langid' in 'class java. lang. integer'

3. correct code:

 

The built-in object _ parameter of mybatis is involved here. When determining a single parameter, it is not directly determined by the parameter object name like 1 and 2. Also, it is best to add the Data Type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.