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

网站设计论文答辩问题排名检测

网站设计论文答辩问题,排名检测,国外购物网站ebay,wordpress加标注插件目录 if where set ctrl alt l格式化SQL语句 随着用户的输入或外部条件的变化而变化的SQL称为动态SQL if <if>用来判断条件是否成立&#xff0c;使用test属性进行条件判断&#xff0c;如果true&#xff0c;则拼接SQL where wehre元素只会在有条件成立的情况下才插入…

目录

if

where

set


ctrl + alt + l格式化SQL语句

 随着用户的输入或外部条件的变化而变化的SQL称为动态SQL

if

<if>用来判断条件是否成立,使用test属性进行条件判断,如果true,则拼接SQL 

where

wehre元素只会在有条件成立的情况下才插入where子句,而且会自动去除开头的AND或OR

如果存在只传递姓名的情况,之前的程序会无法成功查询,可以通过动态SQL解决上述问题 

EmpMapper.xml内容如下

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><!--resultType单条记录所封装的内容--><select id="list" resultType="com.itheima.pojo.Emp">select *from emp<where><if test="name != null">name like concat('%', #{name}, '%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if></where>order by update_time desc</select>
</mapper>

 SpringbootMybatisCrudApplicationTests.java内容如下

package com.itheima;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;@SpringBootTest
class SpringbootMybatisCrudApplicationTests {@Autowiredprivate EmpMapper empMapper;@Testpublic void testSelect(){List<Emp> list = empMapper.list(null,(short)1,null,null);System.out.println(list);}}

 运行结果如下 

set

<set>动态地在行首插入SET关键字,并会删掉额外的逗号(用在update语句中) 

将id为18的员工的username改为Tom111,name改为Tom111,gender改为2,其他不变

按照之前的方法进行更新会使其他值均变为null

可以通过动态SQL解决

EmpMapper.xml内容如下

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><!--resultType单条记录所封装的内容--><update id="update">update emp<set><if test="username != null">username=#{username},</if><if test="password != null">password=#{password},</if><if test="name != null">name=#{name},</if><if test="gender != null">gender=#{gender},</if><if test="image != null">image=#{image},</if><if test="job != null">job=#{job},</if><if test="entrydate != null">entrydate=#{entrydate},</if><if test="deptId != null">dept_id=#{deptId},</if><if test="updateTime != null">update_time=#{updateTime}</if></set>where id=#{id}</update>
</mapper>

EmpMapper.java内容如下 

package com.itheima.mapper;import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;@Mapper
public interface EmpMapper {public void update(Emp emp);}

此次更新id为19的员工,SpringbootMybatisCrudApplicationTests.java内容如下

package com.itheima;import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.time.LocalDateTime;@SpringBootTest
class SpringbootMybatisCrudApplicationTests {@Autowiredprivate EmpMapper empMapper;@Testpublic void testUpdate(){Emp emp = new Emp();emp.setId(19);emp.setUsername("Tom2222");emp.setName("Tom222");emp.setGender((short)1);emp.setUpdateTime(LocalDateTime.now());empMapper.update(emp);}}

 运行结果如下,发现只更新了四个字段,其余字段不变

http://www.zhongyajixie.com/news/61064.html

相关文章:

  • 怎么在自己做的网站上发视频教程百度网址大全网站大全
  • 辽宁食品 中企动力网站建设推广方法有哪几种
  • 合肥网站建设王道下拉??企业网站优化排名
  • php网站做语言包沈阳关键字优化公司
  • 平台门户网站建设网络舆情的网站
  • wordpress 做音乐网站黑科技推广软件
  • 个人微信公众号如何优化百度seo排名
  • 免费域名网站搭建临沂百度公司地址
  • wordpress显示对方ip太原seo优化公司
  • 政务信息网站建设工作孝感seo
  • 企业内部网站宣传方案长春网长春关键词排名站设计
  • 设计网站怎么做新闻稿营销
  • 网站的通栏怎么做网站推广 方法
  • wordpress 4.5.9 漏洞太原seo网站排名
  • 网站三元素怎么做自动发外链工具
  • 乡镇网站建设常见的网络营销工具
  • 网站需要怎么做才能被百度收录站长之家点击进入
  • 营销型网站套餐如何做公司网站推广
  • 深圳公司网站设计企业企业网站建设的作用
  • 网站建设 网站开发互动营销案例都有哪些
  • 电子技术支持 东莞网站建设软件外包公司
  • 大型视频网站建设方案国际军事新闻
  • 杭州建设工程信用平台广州抖音seo
  • 做商贸网站进入百度网首页
  • 做网站游戏推广赚钱吗seo排名需要多少钱
  • 申请号的网站潍坊百度网站排名
  • 宝塔面板怎么做多个网站免费个人自助建站
  • 网站设计自已申请竞价推广代运营服务
  • 做噯噯的网站优化工具箱下载
  • 做网站前端seo搜索是什么意思