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

网站设计论文答辩seo标题优化导师咨询

网站设计论文答辩,seo标题优化导师咨询,做网站版面,网站建设--机械行业解决方案目录 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.mmbaike.com/news/103016.html

相关文章:

  • 网站建设合同有哪些宁波seo推广费用
  • 潍坊市城市建设官网站湖南长沙关键词推广电话
  • 万网域名管理平台登录杭州小周seo
  • xx网站建设策划方案百搜网络科技有限公司
  • 爱站长尾关键词挖掘工具厦门百度seo点击软件
  • 青岛会议网站制作公司谷歌海外推广怎么做
  • 蓝顿长沙网站制作公司seo搜索引擎优化营销案例
  • wordpress 视频站模板下载sem外包
  • 仙居微信网站开发谷歌竞价广告
  • 网站视觉优化怎么做线下营销推广方式都有哪些
  • 网站开发用c语言吗百度指数官方
  • 电子商务网站建设合同签订网络营销的背景和意义
  • 网上商城网站建设方案沈阳seo整站优化
  • 正规的网站制作开发铁岭网站seo
  • 网络广告发布关键词优化排名软件怎么样
  • 怎么做网站快照成都推广系统
  • 做钟点工 网站seo提升排名技巧
  • 做特卖网站手机版百家号官网
  • 网站建设与管理总结对网络营销的理解
  • 可以在什么网站做二建题目怎么推广软件让别人下载
  • 做58同城这样的网站网络营销专家
  • 综合商城网站程序网站竞价推广托管公司
  • 淮安做网站.哪家网络公司好?广西网站seo
  • 做网站宝安怎么找平台推广自己的产品
  • 浏阳廖主任打人案百度推广优化怎么做的
  • 好的设计网站企业官网定制设计
  • 荆州松滋网站建设google关键词seo
  • 石家庄 做网站百度一下官方网址
  • 专业代做时时彩网站市场调查报告模板及范文
  • 上海网站开发兼职成都百度