Mybatis parameter transfer considerations

Source: Internet
Author: User

1

 

Mybatis-there is no getter for property named 'tj 'in 'class java. Lang. string'

Select .. $ {TJ}

 

 An error was reported during the test: There is no getter for property named 'tj 'in 'class java. Lang. string'

 Problem Analysis: mybatis uses the ongl resolution parameter by default, so the string. TJ value is automatically obtained in the form of an object tree, causing an error.

 Solution:Public list methodname (@ param (value = "TJ") string TJ); specifies the parameter value.

Http://bbs.csdn.net/topics/350253850? Page = 1 http://it456.iteye.com/blog/1676864

I. Problems Found

<Select id = "querystudentbynum" resulttype = "student" parametertype = "string">

Select num, name, phone from student
<Where>
<If test = "num! = NULL and num! = ''">
And num = # {num}
</If>
</Where>
</SELECT>

When you pass in a string to the mybatis query, there is no getter for property named 'num' in 'class java. Lang. string' is reported '.

Ii. Solving Problems

<Select id = "querystudentbynum" resulttype = "student" parametertype = "string">

Select num, name, phone from student
<Where>
<If test ="_ Parameter! = NULL and_ Parameter! = ''">
And num = #{_ Parameter}
</If>
</Where>
</SELECT>

Change the parameter name to "_ parameter" or value. For example, "# {value }"

Iii. Cause Analysis

Mybatis uses the ongl resolution parameter by default, so the string. Num value is automatically obtained in the form of an object tree, causing an error. You can also use the public list methodname (@ param (value = "num") string num) method to describe the parameter value.


Refer to blog:

Http://blog.sina.com.cn/s/blog_86e49b8f010191hw.html

Http://txin0814.iteye.com/blog/1533645

 

 

 

Mybatis3 string replacement

In the mybatis3 user guide, the following is the description of string replacement:

String replacement
By default, the syntax in the format of # {} causes mybatis to create the attributes of the pre-processing statement and set it as the background.
Set the security value (such ?). This is safe and quick and preferred practice. Sometimes you just want to directly
Insert a string that does not change. For example, you can use order by as follows:
Order by $ {columnname}
Here, mybatis does not modify or escape strings.
Important: it is not safe to accept the content output from the user and provide it to the constant strings in the statement. This will
This may cause potential SQL injection attacks. Therefore, you should not allow users to enter these fields, or escape and check the fields manually.
Query.

 

When maper XML ing is used

<Select id = "selectcartidbymobileno" parametertype = "string" resulttype = "Java. util. hashmap">
Select car. mobile_no, car. work_record_id from t_car_soure_info car where car. mobile_no in ($ {mobilios })
</SELECT>

The Java call is as follows:

String equalios = "'1970 ***** ', '1970 ****'";

Sqlsession session = sqlmap. getsqlsessionfactory (). opensession ();
Try {
List <Map <string, Object> resultlist = session. selectlist ("selectcartidbymobileno", eNOS NOS );

} Finally {

Session. Close ();

}

When running the command, the following error occurs: mybatis there is no getter for property named 'policenos' in 'class java. Lang. string'

If you change $ to #, no error is reported, but no data can be found.

Finally, change $ {value} to solve this problem.

 

The analysis now shows that the # {} statement is used by default. However, when $ {} is used, the ognl parsing statement is followed because the framework supports ognl, why can I solve this problem by using value? I still don't understand it. I just searched the internet and found someone saying this. Please advise if you understand.

From: http://hi.baidu.com/thinkingjava/item/5b40182c8f8b920c72863ea0

 

 

 

 

 

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.