What is the difference between $ and # In ibatis?

Source: Internet
Author: User

Transferred from:

Http://www.blogjava.net/lsbwahaha/archive/2009/04/16/266026.html

 

When I write an SQL statement in ibatis in a project, where user_id in (# user_id_list #) is always unavailable during running. I checked it online to find out if it was not used #, instead, use $ to check the difference between # and $.
Summary:
1. # It refers to the input data as a string, for example, # user_id_list # If the input is 1 or 2, the SQL statement is generated like this. In ('1, 2'), of course not.

2. $ the incoming data is directly generated in the SQL statement. For example, if # user_id_list # is 1 or 2, the SQL statement is generated. In (1, 2) is correct.

3. # The method can prevent SQL injection to a great extent.

4. The $ method cannot be used for SQL injection.

5. The $ method is generally used to pass in database objects, for example, the table name.

6. Generally, you can use # instead of $.

Intuitively speaking
# STR # The result is 'str'
$ STR $ returns Str

### It can only be used in specific places $ it can be used in any place, such as order by $ STR $

You can even directly write $ STR $ and put the order by string in Str.

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.