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

摄影旅游网站源码网站网络推广软件

摄影旅游网站源码,网站网络推广软件,做网站的都是直男癌吗,wordpress安装教程视频教程需求 : 根据用户的输入情况进行插入 动态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 testgender!nullgender,/if phone) value(#{username},#{password},#{age}, if testgender!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 version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.mybatisdemo.mapper.UserInfo2Mapper/mapper 然后补充代码 ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.mybatisdemo.mapper.UserInfo2Mapperinsert idinsertByXMLinsert into userinfo(username,password,age,if testgender!nullgender,/ifphone)values(#{username},#{password},#{age},if testgender!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.zqtcl.cn/news/423088/

相关文章:

  • 天津商业网站建设搜狗排名优化工具
  • 阿里服务器可以做多少个网站在家怎么利用电脑赚钱
  • 免费建设一个网站google官方版下载
  • 心馨人生珠海网站建设外贸型企业网站建设
  • 好网站建设公司昆明乐清网站优化推广
  • 哪些网站用天平做logo站长工具app官方下载
  • 做餐厅logo用什么软件网站手机自适应网站源码
  • 股票网站模板辽宁工程建设信息网站
  • 毕业设计某网站开发的开题报告范文广西建设教育网站
  • 浏览小城镇建设的网站商丘网站公司
  • python学习网站做好网络推广的技巧
  • 网站有几种类型小说网站开发源码
  • 给城市建设提议献策的网站网站建设可研报告
  • 常德论坛网站陕西建设官方网站
  • 怎么做网站访问量上海网站排名提升
  • 新乡企业网站建设胶州做网站公司
  • 网站后台权限分配说明什么网站是做家教的
  • 网站备案 空间备案 域名备案网站制作与管理技术标准实训教程
  • 东莞免费企业网站模板推广有没有专门做线下活动的网站
  • 驾校网站制作郑州手机网站建设多少钱
  • c2c网站建设策划书怎么看网站关键词密度
  • 网站在线支付方案网站建设 sam大叔排名三天上首页
  • 温岭新站seo网站免费进入窗口软件有哪些
  • 网站未备案什么意思网站 php .net
  • 网站开发第三方登录设计七牛图床 wordpress
  • 大连网站设计案例宁波品牌网站设计价格
  • 响应式表白网站源码黑龙江建设网电话
  • wordpress企业建站生产企业做网站的费用怎么做账
  • 天都城网站建设wordpress pluings
  • 惠州做网站的公司有哪些wordpress主动推送