当前位置: 首页 > news >正文

学校网站建设协议模板公司要做网站去哪里

学校网站建设协议模板,公司要做网站去哪里,客户管理系统admin,如何汇报网站建设3. Mybatis动态SQL 3.1 什么是动态SQL 在页面原型中#xff0c;列表上方的条件是动态的#xff0c;是可以不传递的#xff0c;也可以只传递其中的1个或者2个或者全部。 而在我们刚才编写的SQL语句中#xff0c;我们会看到#xff0c;我们将三个条件直接写死了。 如果页面…3. Mybatis动态SQL 3.1 什么是动态SQL 在页面原型中列表上方的条件是动态的是可以不传递的也可以只传递其中的1个或者2个或者全部。 而在我们刚才编写的SQL语句中我们会看到我们将三个条件直接写死了。 如果页面只传递了参数姓名name 字段其他两个字段 性别 和 入职时间没有传递那么这两个参数的值就是null。 此时执行的SQL语句为 这个查询结果是不正确的。正确的做法应该是传递了参数再组装这个查询条件如果没有传递参数就不应该组装这个查询条件。 比如如果姓名输入了张, 对应的SQL为: select *  from emp where name like %张% order by update_time desc; 如果姓名输入了张,性别选择了男则对应的SQL为: select *  from emp where name like %张% and gender 1 order by update_time desc; SQL语句会随着用户的输入或外部条件的变化而变化我们称为动态SQL。 在Mybatis中提供了很多实现动态SQL的标签我们学习Mybatis中的动态SQL就是掌握这些动态SQL标签。 3.2 动态SQL-if if用于判断条件是否成立。使用test属性进行条件判断如果条件为true则拼接SQL。 if test条件表达式要拼接的sql语句 /if 接下来我们就通过if标签来改造之前条件查询的案例。 3.2.1 条件查询 示例把SQL语句改造为动态SQL方式 原有的SQL语句 select idlist resultTypecom.itheima.pojo.Empselect * from empwhere name like concat(%,#{name},%)and gender #{gender}and entrydate between #{begin} and #{end}order by update_time desc /select 动态SQL语句 select idlist resultTypecom.itheima.pojo.Empselect * from empwhereif testname ! nullname like concat(%,#{name},%)/ifif testgender ! nulland gender #{gender}/ifif testbegin ! null and end ! nulland entrydate between #{begin} and #{end}/iforder by update_time desc /select 测试方法 Test public void testList(){//性别数据为null、开始时间和结束时间也为nullListEmp list empMapper.list(张, null, null, null);for(Emp emp : list){System.out.println(emp);} } 执行的SQL语句 下面呢我们修改测试方法中的代码再次进行测试观察执行情况 Test public void testList(){//姓名为nullListEmp list empMapper.list(null, (short)1, null, null);for(Emp emp : list){System.out.println(emp);} } 执行结果 再次修改测试方法中的代码再次进行测试 Test public void testList(){//传递的数据全部为nullListEmp list empMapper.list(null, null, null, null);for(Emp emp : list){System.out.println(emp);} } 执行的SQL语句 以上问题的解决方案使用where标签代替SQL语句中的where关键字 where只会在子元素有内容的情况下才插入where子句而且会自动去除子句的开头的AND或OR select idlist resultTypecom.itheima.pojo.Empselect * from empwhere!-- if做为where标签的子元素 --if testname ! nulland name like concat(%,#{name},%)/ifif testgender ! nulland gender #{gender}/ifif testbegin ! null and end ! nulland entrydate between #{begin} and #{end}/if/whereorder by update_time desc /select 测试方法 Test public void testList(){//只有性别ListEmp list empMapper.list(null, (short)1, null, null);for(Emp emp : list){System.out.println(emp);} } 执行的SQL语句 3.2.2 更新员工 案例完善更新员工功能修改为动态更新员工数据信息 动态更新员工信息如果更新时传递有值则更新如果更新时没有传递值则不更新 解决方案动态SQL 修改Mapper接口 Mapper public interface EmpMapper {//删除Update注解编写的SQL语句//update操作的SQL语句编写在Mapper映射文件中public void update(Emp emp); } 修改Mapper映射文件 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttps://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.itheima.mapper.EmpMapper ​!--更新操作--update idupdateupdate empsetif testusername ! nullusername#{username},/ifif testname ! nullname#{name},/ifif testgender ! nullgender#{gender},/ifif testimage ! nullimage#{image},/ifif testjob ! nulljob#{job},/ifif testentrydate ! nullentrydate#{entrydate},/ifif testdeptId ! nulldept_id#{deptId},/ifif testupdateTime ! nullupdate_time#{updateTime}/ifwhere id#{id}/update ​ /mapper 测试方法 Test public void testUpdate2(){//要修改的员工信息Emp emp new Emp();emp.setId(20);emp.setUsername(Tom111);emp.setName(汤姆111); ​emp.setUpdateTime(LocalDateTime.now()); ​//调用方法修改员工数据empMapper.update(emp); } 执行的SQL语句 再次修改测试方法观察SQL语句执行情况 Test public void testUpdate2(){//要修改的员工信息Emp emp new Emp();emp.setId(20);emp.setUsername(Tom222);//调用方法修改员工数据empMapper.update(emp); } 执行的SQL语句 以上问题的解决方案使用set标签代替SQL语句中的set关键字 set动态的在SQL语句中插入set关键字并会删掉额外的逗号。用于update语句中 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttps://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.itheima.mapper.EmpMapper ​!--更新操作--update idupdateupdate emp!-- 使用set标签代替update语句中的set关键字 --setif testusername ! nullusername#{username},/ifif testname ! nullname#{name},/ifif testgender ! nullgender#{gender},/ifif testimage ! nullimage#{image},/ifif testjob ! nulljob#{job},/ifif testentrydate ! nullentrydate#{entrydate},/ifif testdeptId ! nulldept_id#{deptId},/ifif testupdateTime ! nullupdate_time#{updateTime}/if/setwhere id#{id}/update /mapper 再次执行测试方法执行的SQL语句 小结 if 用于判断条件是否成立如果条件为true则拼接SQL 形式 if testname ! null … /if where where元素只会在子元素有内容的情况下才插入where子句而且会自动去除子句的开头的AND或OR set 动态地在行首插入 SET 关键字并会删掉额外的逗号。用在update语句中
http://www.pierceye.com/news/785276/

相关文章:

  • 电子商务网站排名辽宁省建设工程信息网业绩公示
  • 天津建设科技杂志的官方网站wordpress cnzz插件
  • 滨州建设网站太原网站建设优化
  • 记事本做网站怎么改字体包装设计模板设计素材
  • 下载软件的网站推荐thinkphp和wordpress
  • 青海省城乡和住房建设厅网站合肥小吃培训网页设计
  • 财经门户网站建设django校园网站开发
  • 泉州网站建设报价广东建设厅网站
  • 建设网站的源代码的所有权wordpress网站打开慢
  • 印度外贸网站有哪些家居小程序源码下载
  • 上海网站建设中心pc官方网站
  • 深圳企业网站制作公司查询西安网站设计哪家好
  • 大埔做网站手机qq邮箱发布了wordpress
  • 寻找南昌网站设计单位网站建设 中企动力医院
  • 中间商可以做网站吗平面广告设计师的工作内容
  • 网站建设用户分析做网站有什么软件
  • 洛阳网站建设启辰网络wordpress怎么破解查看
  • 长沙市网站设计公司厦门建设网站建站
  • 网站做链轮会被惩罚吗网站开发系统
  • 一般做企业网站需要什么资料WordPress情侣博客模板
  • 网站开发教程公司哪些官网用wordpress
  • redis网站开发教程创建app软件
  • 企业网站新闻wp怎么做合肥环保公司网站建设
  • 怎么仿一个复杂的网站wordpress描述怎么改
  • php 如何用op浏览器开发手机网站app开发制作哪种快
  • 网站维护主要有哪些内容和方法网页制作需要学多久
  • 机械加工网站模板做蛋糕比较火的网站
  • 网站的折线图怎么做四川省建设厅官方网站
  • 域名备案 个人 网站基本信息查询wordpress mysql缓存
  • 优秀校园网站建设汇报个人备案的网站