An Analysis of writing like statements in ibatis tutorial

Source: Internet
Author: User

In the ibatis tutorial, how does the like statement look like? There are many examples on the Internet, so this article will introduce some experiences in writing like statements in ibatis.

For the use of the like statement in the ibatis tutorial, We can first look at the use of ibatis on the Internet.
Select * from users where user_name like '% Wang % ';

How to write this like statement in ibatis? The project uses ibatis as the persistent layer framework.

﹤select id="showOneStudentByName" parameterClass="String" resultMap="studentORM﹥" select * from t_stu where s_name like #name#  ﹤/select﹥ 

Obviously, this cannot be written. In the call, % must be added before and after the parameter, for example:

Return sqlmapper. queryforlist ("student. showonestudentbyname", "%" + name + "% ");

This is feasible, but it seems a little uncoordinated.

Finally, the Oracle database is written as follows:

﹤select id="showOneStudentByName" parameterClass="String" resultMap="studentORM"﹥  select * from t_stu where s_name like '%'||#name#||'%'   ﹤/select﹥  

You do not need to add % before and after the call.

Note: Do not write SQL statements as select * From t_stu where s_name like '% $ name $ %', which is vulnerable to injection attacks.

Additional instructions:

Different data string connectors. List MySQL and sqlserver as follows:

MySQL:
Select * from user
Where username like Concat ('%', # username #, '% ')

Sqlserver:
Select * from user

Where username like '%' + # username # + '%'

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.