Mybatis there is no getter for property named ' X '

Source: Internet
Author: User

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 '

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.