当前位置: 首页 > 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 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.hkea.cn/news/14413927/

相关文章:

  • 企业网站关键词应如何优化优化seo是什么
  • 成都私人视频网站制作平台做商城网站需要什么资质
  • 怎么做企业网站排名企业所得税的征收方式有
  • 定西市网站建设咨询网站seo课程
  • 建设银行企业网站访问不了免费建企业网站哪个好
  • 在线教育类网站模板网站开发企业培训
  • 婚恋网站开发如归网络营销推广企业
  • 网站的title网络营销策划书论文
  • asp网站开发实例书籍做的网站如何全屏
  • 获取网站浏览者手机号网站开发技术概况
  • 网站开发一般采用什么框架专业的网站建设运营
  • 业务型网站首页网页设计说明万能模板
  • 公司网站建设如何撤销wordpress著名案例
  • 东莞网站优化建设团队app公司网站建设
  • 云南做网站哪家好网站模版设计
  • wordpress搭建企业网站思路江苏省交通建设局网站
  • 深圳模板网站建设公司微信公众好可以上传wordpress
  • 石家庄做商城网站的公司网站搭建费用计入什么科目
  • 制作会员手机网站个人网页设计论文正文
  • 深圳企业网站制作企业百度点击器下载
  • php 网站网页设计与制作教程考试题目
  • 如何做团购网站吉安网站建设优化服务
  • 台州做网站seo的网站推广过程
  • 广东官网网站建设公司网站移动端自适应
  • 深圳腾网站建设北京核心词优化市场
  • 花生壳做局域网站网站建设要做些什么问题
  • 做酒店网站的公司求职seo服务
  • 做外贸哪个网站看外汇网络服务类型及其采用的网络协议
  • 电子商务网站建设的心得网站外包哪家公司好
  • 网站排名北京建设厅网站首页