网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

MyBatis常用语法和注意事项

1. if

创新互联公司是一家专业从事成都网站制作、成都网站设计、网页设计的品牌网络公司。如今是成都地区具影响力的网站设计公司,作为专业的成都网站建设公司,创新互联公司依托强大的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、营销型网站建设及网站设计开发服务!

    This statement would provide an optional text search type of functionality.

     

    

 

2. choose, when, otherwise

    Sometimes we don’t want all of the conditionals to apply, instead we want to choose only one case among many options.

     

    

 

3. set

    The set element can be used to dynamically include columns to update,and leave out others.

     

    A:

    

      update Author

        

          username=#{username},

          password=#{password},

          email=#{email},

          bio=#{bio}

        

      where id=#{id}

    B:

    

    

      update Author set

          username=#{username},

          password=#{password},

          email=#{email},

          bio=#{bio}

      where id=#{id}

    

     

    Ifbiois null

    A.update Author setusername='xx',password='xx',email ='xx'[not has, due to tag will remove it] where id ='x'

    B.update Author set username ='xx',password='xx',email ='xx', where id ='x'

 

4. foreach

    The foreach element is very powerful, and allows you to specify a collection, declare item and index variables that can be used inside the body of the element. It also allows you to specify opening and closing strings, and add a separator to place in between iterations. The element is smart in that it won’t accidentally append extra separators.

 

    

1. trim

  ...

    Sample:

    select * from user 

    

     AND name=#{name}

     AND gender=#{gender}

    

     

    Ifname andgenderare not null, the SQL will be like this:select * from user where name = 'xx' and gender = 'xx'.

 

    prefix:前缀

    prefixoverride: remove 1st AND/OR

     

    update user

    

     name=#{name} ,

     gender=#{gender},  

    

     

    Ifname andgenderare not null, the SQL will be like this:update user set name='xx' , gender='xx' where id='x'.

    suffix: 后缀

    suffixoverride: remove last character “,”

    where:search condition

    Note

    A)Escape character in MyBatis XML

    Sample:

    where id >= 1(wrong)

    where id >= 1(correct)

     MyBatis常用语法和注意事项

    B)mybatis中#{}和${}的区别

    

    http://www.cnblogs.com/baizhanshi/p/5778692.html

    By default, using the #{} syntax will cause MyBatis to generate PreparedStatement properties and set the values safely against the PreparedStatement parameters (e.g. ?). While this is safer, faster and almost always preferred, sometimes you just want to directly inject a string unmodified into the SQL Statement. For example, for ORDER BY, you might use something like this:

    

 

    ORDER BY ${columnName}

    Here MyBatis won't modify or escape the string.

    

 

    NOTE It's not safe to accept input from a user and supply it to a statement unmodified in this way. This leads to potential SQL Injection attacks and therefore you should either disallow user input in these fields, or always perform your own escapes and checks.


分享标题:MyBatis常用语法和注意事项
文章出自:http://bjjierui.cn/article/pjjpjg.html

其他资讯