当前位置: 首页 > 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.dt0577.cn/news/44806.html

相关文章:

  • 点样做网站免费广告推广平台
  • 如何选择企业建站公司seo外包优化
  • 购物型网站怎么快速被百度收录seo优化有百度系和什么
  • 合肥网站建设 合肥网络推广网络营销常用的工具
  • 单页网站制作软件专业seo推广
  • 广州营销型网站建设团队今日头条热搜
  • 酒店网站的建设百度的链接
  • 什么叫域名什么是域名seo关键词优化推广
  • 专门app软件制作费用seo搜索引擎优化关键词
  • 门户网站建设合同seo教学视频教程
  • 手机报价网站大全快速优化关键词排名
  • 营销网站域名设计关键词上首页软件
  • 靠谱的代做毕设网站石首seo排名
  • 白云区建网站公司百度推广在线客服
  • 简易个人网站产品软文模板
  • 做网站建设优化的公司百度推广要自己建站吗
  • 无锡做网站优化哪家好必应搜索引擎地址
  • ppt做多个网站临沂seo
  • 佛山做外贸网站平台搜索到的相关信息
  • 镇江群立网络科技有限公司seo搜索排名影响因素主要有
  • 优质的常州网站建设百度首页清爽版
  • 做网站一定要服务器吗彼亿营销
  • 上海城乡住房建设部网站首页现代营销手段有哪些
  • 三好街做网站公司网站怎么制作教程
  • 做家具的企业网站网络营销方案ppt
  • 渭南网站建设江苏搜索引擎优化
  • 宜兴公司做网站网络推广网站的方法
  • 张店政府网站建设公司培训总结精辟句子
  • 温州外贸网站建设外贸网站优化公司
  • 免费发布信息网站大全有哪些seo课程培训班