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

wordpress双栏罗湖网站建设优化

wordpress双栏,罗湖网站建设优化,医疗网站建设 飞沐,wordpress 后台登录文章目录 if标签where标签trim标签set标签choose when otherwise批量删除批量插入sql标签与include标签 if标签 1、if标签中的test属性是必须的 2、if标签中test属性的值是false或者true 3、如果test是true#xff0c;则if标签中的sql语句就会拼接#xff0c;反之#xff0… 文章目录 if标签where标签trim标签set标签choose when otherwise批量删除批量插入sql标签与include标签 if标签 1、if标签中的test属性是必须的 2、if标签中test属性的值是false或者true 3、如果test是true则if标签中的sql语句就会拼接反之则不会拼接 4、test属性中可以使用的是 当使用了Param注解那么test中要出现的是Param注解指定的参数名Param“brand”那么这里只能使用brand 当没有使用Param注解那么test中要出现的是param1param2arg0arg1… 当使用了POJO那么test中出现的是POJO类的属性名。 5、在mybatis的动态SQL当中不能使用只能使用and。 //CarMapper.javaListCar selectByMultiCondition(Param(brand)String brand,Param(guidePrice) Double guidePrice,Param(carType) String carType);!-- CarMapper.xml --select idselectByMultiCondition resultTypeCarselect * from t_car whereif testbrand ! null and brand ! brand like %#{brand}%/ifif testguidePrice ! null and guidePrice ! and guide_price #{guidePrice}/ifif testcarType ! null and carType ! and car_type #{carType}/if/select//CarMapperTest.javaTestpublic void testSelectById(){SqlSession sqlSession SqlSessionUtil.openSession();CarMapper mapper sqlSession.getMapper(CarMapper.class);ListCar cars mapper.selectByMultiCondition(比亚迪,2.0,新能源);cars.forEach(car - System.out.println(car));sqlSession.close();}↑但是上面写的SQL语句明显存在着逻辑的问题如果第一个判断语句为false里面的SQL语句没有执行而后面的加上了就存在SQL语句的语法错误 所以改为下面这种语句 select idselectByMultiCondition resultTypeCarselect * from t_car where 1 1if testbrand ! null and brand ! and brand like %#{brand}%/ifif testguidePrice ! null and guidePrice ! and guide_price #{guidePrice}/ifif testcarType ! null and carType ! and car_type #{carType}/if/selectwhere标签 where标签的作用让where子句更加多态智能 所有条件都为空时where标签保证不会生成where子句。自动去除某些条件前面多余的and或or wher标签是专门负责where子句动态生成的 select idselectByMultiConditionWhere resultTypeCarselect * from t_carwhereif testbrand ! null and brand ! and brand like %#{brand}%/ifif testguidePrice ! null and guidePrice ! and guide_price #{guidePrice}/ifif testcarType ! null and carType ! and car_type #{carType}/if/where/selecttrim标签 trim标签的属性 prefix在trim标签中的语句前添加内容suffix在trim标签中的语句后添加内容prefixOverrides前缀覆盖掉去掉suffixOverrides后缀覆盖掉去掉 select idselectByMultiConditionTrim resultTypeCarselect * from t_cartrim prefixwhere suffixOverridesand|orif testbrand ! null and brand ! brand like %#{brand}% and/ifif testguidePrice ! null and guidePrice ! guide_price #{guidePrice} and/ifif testcarType ! null and carType ! car_type #{carType}/if/trim/selectprefixwhere是在trim标签所有内容的前面添加wheresuffixOverridesand|or把trim标签中内容的后缀and或or去掉 set标签 主要使用在update语句当中用来生成set关键字同时去掉最后多余的“” 比如我们只更新提交的不为空的字段如果提交的数据是空或者“ ”那么这个字段我们将不更新 int updateWithSet(Car car)update idupdateWithSetupdate t_carsetif testcarNum ! null and carNum ! car_num #{carNum},/ifif testbrand ! null and brand ! brand #{brand},/ifif testguidePrice ! null and guidePrice ! guide_price #{guidePrice},/ifif testproduceTime ! null and produceTime ! produce_time #{produceTime},/ifif testcarType ! null and carType ! car_type #{carType}/if/setwhere id #{id}/updateTestpublic void testBySet(){SqlSession sqlSession SqlSessionUtil.openSession();CarMapper mapper sqlSession.getMapper(CarMapper.class);Car car new Car(5L,null,null,丰田sucker,null,null);mapper.updateWithSet(car);sqlSession.commit();sqlSession.close();}choose when otherwise 这三个标签是在一起使用的 相当于if、elseif、else 只有一个分支会被选择 ListCar selectByChoose(Param(brand)String brand,Param(guidePrice)Double guidePrice,Param(carType)String carType);select idselectByChoose resultTypeCarselect * from t_carwherechoosewhen testbrand ! null and brand ! brand like %#{brand}%/whenwhen testguidePrice ! null and guidePrice ! guide_price #{guidePrice}/whenotherwisecar_type #{carType}/otherwise/choose/where/selectTestpublic void testchoose(){SqlSession sqlSession SqlSessionUtil.openSession();CarMapper mapper sqlSession.getMapper(CarMapper.class);ListCar cars mapper.selectByChoose(, 5.0,null);cars.forEach(car - System.out.println(car));sqlSession.close();}批量删除 int deleteByIds(String ids[]);foreach标签的属性 collection指定数组或者集合item代表数组或集合中的元素separator循环之间的分隔符 delete iddeleteByIdsdelete from t_car where id in(foreach collectionids itembaga separator,#{baga}/foreach)/deleteTestpublic void testDelteAll(){SqlSession sqlSession SqlSessionUtil.openSession();CarMapper mapper sqlSession.getMapper(CarMapper.class);Long[] ids {7L, 8L, 9L};int i mapper.deleteByIds(ids);System.out.println(i);sqlSession.commit();sqlSession.close();}批量插入 int insertBatch(Param(cars)ListCar cars);insert idinsertBatchinsert into t_car valuesforeach collectioncars itemcar separator, (null,#{car.carNum},#{car.brand},#{car.guidePrice},#{car.carType},#{car.produceTime})/foreach/insertTestpublic void testInsertBatch(){SqlSession sqlSession SqlSessionUtil.openSession();CarMapper mapper sqlSession.getMapper(CarMapper.class);Car car1 new Car(null,八嘎亚路1,30.8,燃油第,null,111);Car car2 new Car(null,八嘎亚路2,30.8,燃油第,null,111);Car car3 new Car(null,八嘎亚路3,30.8,燃油第,null,111);ListCar cars new ArrayList();cars.add(car1);cars.add(car2);cars.add(car3);mapper.insertBatch(cars);sqlSession.commit();sqlSession.close();}sql标签与include标签 sql标签用来声明sql片段 include标签用来将声明的sql片段包含到某个sql语句当中 作用代码复用易维护 sql idcarColumnNameSqlid,car_num as carNum,brnd,guide_price as guidePrice,produce_time as produceTime,car_type as carType /sql select id.... resultTypecarselectinclude refidcarColumnNameSqlfrom t_car where id #{id} /select
http://www.pierceye.com/news/668660/

相关文章:

  • 学网站开发培训学校专业集团门户网站建设费用
  • 加快政务公开网站建设知名的摄影网站有哪些
  • 任县网站建设网络公司桐城网站开发
  • linux服务器做网站软装设计图效果图
  • 个人网站可以做商城吗被官方认可赚钱软件
  • 自己可以做网站服务器室内设计整套方案图
  • 网站建设商城网站微信广告代理
  • 创建网站的方案企业营销策划公司
  • 做彩铃的网站个人博客网站建设
  • 正黄集团博弘建设官方网站达州高端网站建设
  • 七台河建设网站wordpress logo制作
  • 怎么设计一个自己的网站番禺网站建设效果
  • 网站哪家做的好淄博网站开发选网泰
  • 网站建设与制作与维护ppt百度广告联盟收益
  • 在线网站建设费用是多少大学生活动策划书模板
  • 动物网站建设wordpress无法跳转正确页面
  • 上海市建设工程 安全协会网站wordpress会员微信支付宝
  • pc网站转换手机网站代码桂林工作网招聘
  • 营销型网站建设的要素怎么建网站赚钱
  • 成都网站建设学习郑州制作网站推荐
  • 网站建设 镇江丹阳php网站开发实例教程代码
  • 佛山外贸网站建设方案专业网站建设系统
  • 做一个网站团队需要哪些人员花钱也可以哪些网站可以做推广广告
  • 各省施工备案网站做动漫网站的素材
  • 新余网站设计网站模板做网站
  • 防止服务器上的网站被进攻app推广兼职
  • 保定电商网站建设国内最好的crm软件
  • 企业网站建设哪家公司好莱芜金点子信息港房产网
  • 个人可以建设网站吗海淀网站建设本溪
  • 宜昌网站建设兼职怎样做自媒体拍视频赚钱