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

做网站需要多少钱一个月百度指数分析官网

做网站需要多少钱一个月,百度指数分析官网,如何在网站投放广告,外链生成需求 : 根据用户的输入情况进行插入 动态SQL:根据需求动态拼接SQL 用户往表中插入数据,有的数据可能不想插入,比如不想让别人知道自己的性别,性别就为空 insert into userinfo(username,password,age,gender,phone) values(?,?,?,?,?); insert into userinfo(username,…

需求 : 根据用户的输入情况进行插入

动态SQL:根据需求动态拼接SQL

用户往表中插入数据,有的数据可能不想插入,比如不想让别人知道自己的性别,性别就为空

insert into userinfo(username,password,age,gender,phone) values(?,?,?,?,?);
insert into userinfo(username,password,age,gender) values(?,?,?,?);
insert into userinfo(username,password,age,phone) values(?,?,?,?);

接下来看看 mybatis 注解的方式该如何实现动态SQL,新建了一个 userInfo2Mapper 接口

<if>标签里面的意思是 : 如果gener不为null,那就输出if标签的内容

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;import java.util.List;@Mapper
public interface UserInfo2Mapper {@Insert("<script>" +" insert into userinfo(username,password,age," +"<if test='gender!=null'>gender,</if>" +"phone) " +"value(#{username},#{password},#{age}," +"<if test='gender!=null'>#{gender},</if>" +"#{phone})" +"</script>")Integer insert(UserInfo userInfo);
}

 然后老样子,Generate,test,勾选 insert ,然后补充代码,我们先每个数据都插入内容

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.UserInfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest
class UserInfo2MapperTest {@Autowiredprivate UserInfo2Mapper userInfo2Mapper;@Testvoid insert() {UserInfo userInfo = new UserInfo();userInfo.setUsername("kiki");userInfo.setPassword("555www");userInfo.setAge(23);userInfo.setGender(1);userInfo.setPhone("177966");userInfo2Mapper.insert(userInfo);}
}

插入成功 

数据库中也能成功找到刚刚插入的数据 

接下来我们要测试性别为空的情况,把 test代码里面的 userinfo.setGender 给去掉, 再次运行

 数据库也能找到,说明性别为空也插入成功了

上面是注解的方式,接下来我们看看 XML 的方式该如何实现 

在resources 中创建 Userinfo2XMLMapper.xml 文件

然后在 userInfo2Mapper 接口 中声明这个方法

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;import java.util.List;@Mapper
public interface UserInfo2Mapper {Integer insertByXML(UserInfo userInfo);
}

将 Userinfo2XMLMapper.xml 文件中的 namespace 进行修改,改为 userInfo2Mapper 接口中的第一行 package 的内容再加上接口名

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mybatisdemo.mapper.UserInfo2Mapper"></mapper>

然后补充代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mybatisdemo.mapper.UserInfo2Mapper"><insert id="insertByXML">insert into userinfo(username,password,age,<if test="gender!=null">gender,</if>phone)values(#{username},#{password},#{age},<if test="gender!=null">#{gender},</if>#{phone})</insert>
</mapper>

再回到接口,然后Generate,test,勾选insertByXML,ok,先测试每个数据都插入的情况

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.UserInfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest
class UserInfo2MapperTest {@Autowiredprivate UserInfo2Mapper userInfo2Mapper;@Testvoid insertByXML() {UserInfo userInfo = new UserInfo();userInfo.setUsername("io");userInfo.setPassword("555www");userInfo.setAge(23);userInfo.setGender(1);userInfo.setPhone("177966");userInfo2Mapper.insertByXML(userInfo);}
}

成功插入

再把 userinfo.setGender 给去掉,再次运行

 

 没毛病

http://www.yayakq.cn/news/385347/

相关文章:

  • 网站建设的目标用户是泸州网站建设多少钱
  • 网站建站公司费用建设海外网站
  • 行业电子网站建设如何制作自媒体短视频
  • 湖南建设厅网站不良记录站群子网站开发
  • 创办一个网站要多少钱上海广告公司网站制作
  • 陕西省网站开发wordpress后台在哪里设置段落间距
  • 广州网站设计后缀分类信息网站如何优化
  • 专业做简历的网站义乌网站建设公司
  • 主机做网站中国建设银行个人网站登录
  • 网站制作那家便宜中国网站排名榜
  • 如何做条形码网站怎么搞邢台pc网站开发
  • 中山台州网站建设推广沈阳网站开发集团
  • 河北省建设工程招标投标网站学做西餐的网站
  • 学做衣服网站有哪些东莞高森网络营销
  • 个人主页网站html单位如何申请域名
  • 福建省建设厅网站投诉aaa云主机怎么做网站
  • 一篇关于大学网站建设与管理的论文怎么上传做 好的网站吗
  • 公司网站文案推广怎么做上海制作网站的公司有哪些
  • 上海阿里巴巴做网站网站建设的竞争力
  • 网站开发技术选择导视设计ppt
  • 站长工具端口检测官网如何做广告推广
  • 网站建设小说毕业设计建设外贸英文网站
  • wordpress怎么收费长沙关键词优化新行情报价
  • 流量网站建设教程网站软文推广范文
  • 免费网站模块新手建立企业网站流程
  • 网站改版设计思路一个完美的网站怎么做
  • 17网站一起做网店普宁批量扫dedecms做的网站
  • 外网代理服务器网站快速推广
  • 怎么建设淘客自己的网站_做网站的公司哪家有名
  • 做网站双12促销方案wordpress修改插件路径