This problem is encountered in dynamic SQL that tries to use MyBatis.
When using a MyBatis query, its parameters can be basic data types or simple data objects such as Integer and string, or complex objects (usually referred to as JavaBean) or maps, when using parameters of the base data type, If the use of this parameter is placed in the judging condition,
<!--mybatis dynamic sql--><select id= "Findfruit" resulttype= "Fruit" > select * from tb_fruit WHERE name = ' Hel Loworld ' <if test= "Tyep! = null" > and type = #{_parameter} </if></select>
Inquire
@Testpublic void test8837 () throws SQLException {sqlsession sqlsession = sqlsessionfactory.opensession (); Sqlsession.getconnection (). Setautocommit (True); Sets the automatic commit of the transaction list<fruit> fruits = sqlsession.selectlist ("Com.usoft.mapper.FruitMapper.findFruit", null); list<fruit> fruits2 = sqlsession.selectlist ("Com.usoft.mapper.FruitMapper.findFruit", 1); System.out.println (Fruits.size ()); System.out.println (Fruits2.size ()); Sqlsession.close ();}
The following error will be reported,
Org.apache.ibatis.exceptions.PersistenceException:
# # # Error querying database. Cause:org.apache.ibatis.reflection.ReflectionException:There is the no getter for property named ' Tyep ' in ' class Java.lang. Integer '
# # Cause:org.apache.ibatis.reflection.ReflectionException:There is no getter for property named ' Tyep ' in ' class JAVA.L Ang. Integer '
That is, the integer class does not have the type of this property, Ah, there is no type in the integer this property ah, in fact, in MyBatis, the use of Ongl parsing parameters, so will automatically take the form of object tree to get the value of the variable passed in. The type of the passed parameter here is int, which is automatically boxed as an integer, and when the value of the type parameter is obtained, the type value of the integer is actually obtained. So this is not the right way of writing.
Should be changed to the following,
<!--mybatis dynamic sql--><select id= "Findfruit" resulttype= "Fruit" > select * from tb_fruit WHERE name = ' Hel Loworld ' <if test= "_parameter! = null" > and type = #{_parameter} </if></select>
The _parameter here indicates that the type of the parameter is a primitive type or a basic type of package type.
==========================end==========================
Mybatis there is no getter for property named ' X '