Mybatis single parameter if judgment (for exception: There is no getter for property...), mybatisgetter
We all know that mybatis can directly use <if test = ""> </if> to determine the parameters, as shown below:
1. General Code
<update id="update" parameterType="com.cq2022.zago.order.entity.Test" > update t_test_l <set > <if test="trnsctWayId != null" > trnsct_way_id = #{trnsctWayId,jdbcType=TINYINT}, </if> <if test="langId != null" > lang_id = #{langId,jdbcType=INTEGER}, </if> </set> where trnsct_way_l_id = #{trnsctWayLId,jdbcType=INTEGER} </update>
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