When the MyBatis parameter is list, verifies that the list is empty, MyBatis ${} differs from #{}, MyBatis SQL in

Source: Internet
Author: User

1, when the MyBatis parameter is list, check whether the list is empty

2. The difference between MyBatis ${} and #{}

In short, #{} is a placeholder? can prevent SQL injection, such as the printed statement select * FROM table where id=?
However, ${} is a statement that cannot prevent SQL injection from being printed out of a select * from table where id=2 is a  real parameter.
The simplest difference is that the ${} parse passes through the parameter values without single quotes, #{} parse passes over the parameters with single quotes.
Finally summarize the case that you must use the $ reference parameter, which is the int of the parameter, you must use the $ reference.

3. Mybatis SQL in
Parameter Pass List
1 <SelectID= "Findbyidsmap"Resultmap= "Baseresultmap">  2 Select3  <includerefID= "Base_column_list" />  4 From Jria where ID in5  <foreachItem= "Item"Index= "Index"Collection= "List"Open="("Separator=","Close=")">  6 #{item}7  </foreach>  8 </Select>  

When the MyBatis parameter is list, verifies that the list is empty, MyBatis ${} differs from #{}, MyBatis SQL in

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.