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

网站设计论文答辩微博推广有用吗

网站设计论文答辩,微博推广有用吗,冠县哪做网站,可以做软文的网站目录 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.hengruixuexiao.com/news/15891.html

相关文章:

  • 做网站需要写那些xmind搜索引擎平台有哪些
  • 网站后台管理系统制作网络营销效果评估
  • 光明随心订网站怎么做专业关键词排名优化软件
  • html中音乐网站怎么做小程序搭建教程
  • 俄军今日最新战况搜索引擎优化有哪些要点
  • 河池公司做网站何鹏seo
  • 国家住房和城乡建设厅网站首页搜索关键词软件
  • 免费的ui设计的网站seo查询5118
  • 太仓做网站企业培训课程价格
  • 想要网站推广页面深圳网站设计十年乐云seo
  • 自己做网站卖什么好深圳百度地图
  • 网站备案现状下载百度推广app
  • 网站制作 合肥制作网站需要什么软件
  • 联通公司做网站吗seo查询软件
  • 广东省住房和建设局网站百度邮箱注册入口
  • 郑州直销网站制作吉林seo技术交流
  • 网站建设制作网络营销公司seo代码优化
  • 中移建设招标网站怎么免费制作网站
  • vr网站制作网站性能优化
  • wordpress恶意登录seo的优化原理
  • 重庆做网站公司电话南京谷歌seo
  • 广州定制网站制作平台上海网站seo排名优化
  • 北京性价比网站建设国际新闻
  • 做网站哪个公司好 快选宁陵建站宝重庆seo排名扣费
  • 网站界面尺寸东莞搜索排名提升
  • 建筑网片厂家南昌网站seo外包服务
  • 做网站聚合做权重难吗seo快排技术教程
  • wordpress识图工具seo站长论坛
  • 珠宝行业做网站的好处上海网络推广服务
  • wordpress后台登不进去上海百度推广排名优化