网站大量收购独家精品文档,联系QQ:2885784924

Java EE企业级应用开发第8章 动态SQL.ppt

  1. 1、本文档共30页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
8.4 where、trim元素 where、trim元素 select * from t_customer where 1=1 choose when test=username !=null and username != and username like concat(%,#{username}, %) /when when test=jobs !=null and jobs != and jobs= #{jobs} /when otherwise and phone is not null /otherwise /choose 针对上述情况中“where 1=1”,在MyBatis的SQL中就可以使用where或trim元素进行动态处理。 where会自动判断SQL语句,只有where内的条件成立时,才会在拼接SQL中加入where关键字,否则将不会添加;还会去除多余的“AND”或“OR”。 where元素处理 trim元素处理 trim的作用是去除特殊的字符串,它的prefix属性代表语句的前缀,prefixOverrides属性代表需要去除的哪些特殊字符串,功能和where基本是等效的。 动态SQL处理 “where 1=1” select * from t_customer where if test=username !=null and username != and username like concat(%,#{username}, %) /if if test=jobs !=null and jobs != and jobs= #{jobs} /if /where select * from t_customer trim prefix=where prefixOverrides=and if test=username !=null and username != and username like concat(%,#{username}, %) /if if test=jobs !=null and jobs != and jobs= #{jobs} /if /trim 主讲内容 主讲内容 Speech content 8.1 动态SQL中的元素 8.4 when、trim元素 8.5 set元素 8.6 foreach元素 8.7 bind元素 8.2 if元素 8.3 choose及其子元素 8.5 set元素 set元素 select * from t_customer where 1=1 choose when test=username !=null and username != and username like concat(%,#{username}, %) /when when test=jobs !=null and jobs != and jobs= #{jobs} /when otherwise and phone is not null /otherwise /choose 在Hibernate中,想要更新某个对象,就需要发送所有的字段给持久化对象,这种想更新的每一条数据都要将其所有的属性都更新一遍的方法,其执行效率是非常差的。为此,在MyBatis中可以使用动态SQL中的set元素进行处理: update id=updateCustomer parameterType=com.itheima.po.Customer update t_customer set if test=username !=null and username != username=#{username}, /if if test=jobs !=

您可能关注的文档

文档评论(0)

132****9295 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档