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

长沙网站设计网站专题模板

长沙网站设计,网站专题模板,seo入门讲解,网站信息可以边建设边组织if标签与where标签 if标签 test如果为true就会拼接查询条件&#xff0c;否则不会 当没有使用Param&#xff0c;test出现arg0/param1当使用Param&#xff0c;test为Param指定的值当使用Pojo&#xff0c;test为对象的属性名 select * from car where <if test"name!n…

if标签与where标签

if标签

test如果为true就会拼接查询条件,否则不会

  • 当没有使用@Param,test出现arg0/param1
  • 当使用@Param,test为@Param指定的值
  • 当使用Pojo,test为对象的属性名
select * from car where
<if test="name!=null || name!='' ">name like concat('%',${name},'%')
</if>
<if test="price!=null || price!='' ">and price=#{price}
</if>
...

注意日期不能判断为空字符串

如何所有条件都不满足上述代码会报错

解决

如果用 where 1=1 后面判断必须加and

select * from car where 1=1
<if test="name!=null || name!='' ">and name like concat('%',${name},'%')
</if>
<if test="price!=null || price!='' ">and price=#{price}
</if>
...

where标签

  • 所有条件都为空时,where子句不会生成
  • 自动去掉前面多余的and,or
select * from car 
<where><if test="name!=null || name!='' ">name like concat('%',${name},'%')</if><if test="price!=null || price!='' ">and price=#{price}</if>
</where>
...

trim标签

  • prefix在标签前面动态的添加属性值
  • suffix在标签后面动态的添加属性值
  • suffixOverrides去除标签内容后面中指定的属性值
  • prefixOverrides去除标签内容前面中指定的属性值
select * from car 
<trim prefix="where" suffixOverrides="and | or" prefixOverrides="" suffix=""><if test="name!=null || name!='' ">name like concat('%',${name},'%')</if><if test="price!=null || price!='' ">and price=#{price}</if>
</trim>

set标签

  • 主要用在update标签中,只会提交不为空的条件
  • 可以动态去除语句中多余的,
update  car 
<set><if test="name!=null || name!='' ">name=#{name} , </if><if test="price!=null || price!='' ">price=#{price} ,</if>
</set>
where id=#{id}

choose when otherwise标签

一般在多条件中只执行某一个条件查询

用法类似与 if else if else

selecr * from car
<where><choose><when test="name!=null || name!='' ">name=#{name} </when><when test="price!=null || price!='' ">price=#{price} </when><otherwise>id=#{id} <otherwise></choose>
<where>

因为只会满足一种查询条件所有不需要加and


forEach标签

  • collection为循环列表
  • item为循环元素
  • separator为循环元素之间的分隔符
  • open为标签前面加属性值
  • close为标签后面加属性值

批量删除

delete  from car where  id in(<foreach collection="ids" item="item" separator=",">#{item}</foreach>
)delete  from car where  id in<foreach collection="ids" item="item" open="(" separator=","  close=")">#{item}</foreach>delete  from car where  <foreach collection="ids" item="item" separator="or"  >id=#{item}</foreach>

批量插入

insert into  car( name, price)
values<foreach collection="list" item="item" separator=",">(#{item.name},#{item.price})</foreach>

sql与include标签

主要用于字段的封装和复用

<sql id="CarSql">id,car_num as  carNum,brand,guide_price as guidePrice,produce_time as produceTime,car_type as carType
</sql><select id="selectAll" resultType="com.example.webapplication.pojo.Car">select<include refid="CarSql"></include>from car
</select>
http://www.yayakq.cn/news/340664/

相关文章:

  • 英文公司网站制作网站建设公司的未来
  • 阿里云突发性能适用于做网站吗宁夏建设教育协会网站
  • 有哪些调查网站可以做兼职岑巩网站建设
  • h5素材做多的网站股票专业网站
  • 宜宾县企业项目建设影响环境登记表网站网站友链查询接口
  • 律师如何在网上推广seo优化推广流程
  • 较好的网站模板济南品牌营销型网站建设
  • 高水平的锦州网站建设网站开发网站排名优化
  • wordpress cms 下载广东网站seo策划
  • 网站服务器被黑怎么办专业seo排名优化费用
  • 福安市教育局建设网站面试个人简历范文及网站建设
  • 南宁网站建设公司如何为老板打造网站赚钱的wordpress移动端底部导航栏
  • 设计网站还有哪些问题wordpress换域名主题
  • 做互联网小程序 和网站有没有前景计算机网络维护工作内容
  • 搭建什么网站能盈利去年做啥网站致富
  • 企业形象宣传策划方案seo如何快速排名
  • 长沙网站建设哪家最好中华室内设计网怎么样
  • 公众号里的网站怎么做诸城网站价格
  • 网站服务器有哪几种企业app软件开发公司
  • 无锡工程建设招标网站带域名的网站打不开
  • 电子邮箱网站建设百度云无法进入wordpress
  • 做网站月入5万局域网里做网站
  • 三亚市住房与城乡建设局网站应用商店关键词优化
  • 中山快速做网站公司打开上次浏览的网站模板
  • 山东建设银行怎么招聘网站北京seo网站
  • 好建网站完全静态化成wordpress
  • 南宁做网站比较好的公司wordpress反应
  • 电子商务网站建设与维护论文佛山专业网站建设报价
  • 微信网站建设新闻全国建设厅网站
  • 招聘网站设计论文我想做代理商