Problem code:
<select id="selectIstars" parameterType="java.lang.String" resultType="java.lang.String"> SELECT stars FROM book WHERE 1 = 1 <if test="id != null"> AND id = #{id,jdbcType=VARCHAR} </if> </select>
This is the problem with the final positioning code, which has been roughly understood by many online references:
There is a difference between the judgment of single parameter and multi parameter. When our input parameter is an entity class or map, there is no problem using the if parameter.
But when our input parameter is java.lang.integer or java.lang.string, we need to pay attention to some things
For integer type input parameters, add this
#{id,jdbcType=integer}
There is a problem with the input parameter of string type. I also added it
#{id,jdbcType=VARCHAR}
It still reported an error. Finally, the if judgment was deleted and the problem was solved, but it was still confused. If a big man understands it, please give me some advice