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

网站推广策划内容移动端网站模板

网站推广策划内容,移动端网站模板,怀化灵知网站建设,有哪些网站可以做推文目录 一、删除 #xff08;1#xff09;在mapper接口执行sql删除语句 ① 注解后sql语句没有提示怎么办#xff1f; #xff08;2#xff09;测试层 #xff08;3#xff09;开启mybatis日志 #xff08;4#xff09;预编译SQL 二、新增 #xff08;1#… 目录 一、删除 1在mapper接口执行sql删除语句 ① 注解后sql语句没有提示怎么办 2测试层  3开启mybatis日志 4预编译SQL  二、新增 1新增信息 2主键返回 三、更新 四、查询 1简单查询 当字段名与属性名不一致时mybatis不封装 ​ ① 解决办法1 ② 解决办法2 2条件查询 五、定义XML映射文件 1在resource文件下创建【与mapper接口所在包名一致】的目录文件  2在该目录下新建file文件 3在xml文件中搭建基础结构 ① 获取接口全类名方法 4配置sql语句 ① 定义方法名后如何快速在xml文件中生成对应标签 六、动态SQL 1if 2foreach 3sqlinclude 一、删除 1在mapper接口执行sql删除语句 ① 注解后sql语句没有提示怎么办 Mapper public interface EmpMapper {//根据id删除数据Delete(delete from emp where id #{id})public void delete(Integer id); } 2测试层  SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textDelete() {empmapper.delete(17);} } 3开启mybatis日志 在application.properties配置日志 mybatis.configuration.log-implorg.apache.ibatis.logging.stdout.StdOutImpl 4预编译SQL  更高效采用?占位符java发送语句的同时发送参数后续因为缓存已经有编译好的sql语句直接可以执行 更安全防止SQL注入SQL注入是通过操作输入的数据来修改事先定义好的SQL语句以达到执行代码对服务器进行攻击的方法 二、新增 1新增信息 注意#{}内采用【驼峰命名法】即_用大写字母替代egdept_id → deptId Mapper public interface EmpMapper {//新增员工Insert(insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime}))public void insert(Emp emp); } SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textInsert() {Emp emp new Emp();emp.setName(tom);emp.setUsername(TOM);emp.setImage(1.jpg);emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2000,1,1));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setId(1);empmapper.insert(emp);}2主键返回 在数据添加成功后需要获取插入数据的主键。eg添加套餐数据时需要返回套餐id来维护套餐-菜品关系 会将自动生成的主键值赋值给emp对象的id属性 Options(keyProperty id,useGeneratedKeys true) //新增员工Options(keyProperty id,useGeneratedKeys true)Insert(insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime}))public void insert(Emp emp);三、更新 根据id更新员工信息 Mapper public interface EmpMapper {//更新员工Update(update emp set username #{username} ,name #{name},gender #{gender},image #{image},job #{job},entrydate #{entrydate},dept_id #{deptId},update_time #{updateTime} where id #{id})public void update(Emp emp); } SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textInsert() {Emp emp new Emp();emp.setName(kakak);emp.setUsername(88kakk);emp.setImage(1.jpg);emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2000,1,1));emp.setUpdateTime(LocalDateTime.now());emp.setId(18);emp.setDeptId(1);empmapper.update(emp);} } 四、查询 1简单查询 Mapper public interface EmpMapper {//根据id查询员工Select(select * from emp where id #{id})public Emp getById(Integer id); } SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textInsert() {Emp emp empmapper.getById(19);System.out.println(emp);} } 当字段名与属性名不一致时mybatis不封装 ① 解决办法1 手动注解 Mapper public interface EmpMapper {//根据id查询员工Results({Result(column dept_id,property deptId),Result(column crea_time,property createTime),Result(column update_time,property updateTime)})Select(select * from emp where id #{id})public Emp getById(Integer id); } ② 解决办法2 在application.properties开启驼峰命名法开关 # 开启驼峰命名法自动映射开关 mybatis.configuration.map-underscore-to-camel-casetrue 2条件查询 #{}编译后会被?替代但?不能出现在‘’内因此我们不能使用#{}而要使用拼接${}但是${}有sql注入风险因此我们使用concat()字符串拼接函数  Mapper public interface EmpMapper {//根据id查询员工Select(select * from emp where name like %${name}% and gender #{gender} and entrydate between #{begin} and #{end})public ListEmp list(String name, Short gender, LocalDate begin,LocalDate end); } Mapper public interface EmpMapper {//根据id查询员工Select(select * from emp where name like concat(%,#{name},%) and gender #{gender} and entrydate between #{begin} and #{end})public ListEmp list(String name, Short gender, LocalDate begin,LocalDate end); } SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textList() {ListEmp empList empmapper.list(张,(short)1,LocalDate.of(2010,1,1),LocalDate.of(2020,1,1));System.out.println(empList);} } 五、定义XML映射文件 注解开发简单的sqlxml开发动态sql 1在resource文件下创建【与mapper接口所在包名一致】的目录文件  2在该目录下新建file文件 文件名与mapper接口名一致 3在xml文件中搭建基础结构 namespace属性和mapper接口全类名一致 MyBatis中文网 ① 获取接口全类名方法 ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtdmapper namespacecom.itheima.mapper.EmpMapper/mapper 4配置sql语句 id与mapper接口中方法名一致保持返回类型一致 resultType和类名一致 ① 定义方法名后如何快速在xml文件中生成对应标签 把光标置于方法名上按alt回车回车直接跳转到xml文件并生成  六、动态SQL 随着用户的输入或外部条件变化而变化的SQL语句称为动态SQL 比方说查询框有姓名性别入职时间 用户如果不填某空缺少某参数用之前注解sql语句肯定会报错而动态sql就是解决这一问题的 1if 如果test属性成立则拼接SQL mapper namespacecom.itheima.mapper.EmpMapper!-- resultType:单条记录所封装的类型--select idlist resultTypecom.itheima.pojo.Empselect *from empwhereif testname ! nullname like concat(%, #{name}, %)/ifif testgender ! nulland gender #{gender}/ifif testbegin ! null and end ! nulland entrydate between #{begin} and #{end}/if/whereorder by update_time desc/select/mapper 2foreach 批量删除 collection遍历的集合item遍历出来的元素separator分隔符open遍历开始前拼接的SQL片段close遍历结束后拼接的SQL片段 mapper namespacecom.itheima.mapper.EmpMapper !-- 批量删除员工(18,19,20)--delete iddeleteByIdsdelete from emp where id inforeach collectionids itemx separator, open( close)#{x}/foreach/delete /mapper SpringBootTest class MybatisCrudApplicationTests {Autowiredprivate EmpMapper empmapper;Testpublic void textList() {ListInteger ids Arrays.asList(13,14,15);empmapper.deleteByIds(ids);} } 3sqlinclude sql标签可以择出重复使用的语句并用include在所需要的地方引/ mapper namespacecom.itheima.mapper.EmpMappersql idcommonSelectselect id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_timefrom emp/sql!-- resultType:单条记录所封装的类型--select idlist resultTypecom.itheima.pojo.Empinclude refidcommonSelect/whereif testname ! nullname like concat(%, #{name}, %)/ifif testgender ! nulland gender #{gender}/ifif testbegin ! null and end ! nulland entrydate between #{begin} and #{end}/if/whereorder by update_time desc/select/mapper
http://www.dnsts.com.cn/news/172329.html

相关文章:

  • 网站问题分析做网站需要接口么
  • 一般网站字体平度市城乡建设局网站
  • 织梦网站会员上传图片企业培训心得体会
  • 米拓建站官网怎么用不了戚墅堰常州做网站
  • 深圳专业做网站建网站德州网页制作
  • 石碣镇做网站财经门户网站开发
  • 姑苏区做网站网站建设项目组工作总结
  • 网站开发软件科技公司学校网站的服务器
  • 织梦cms怎么打不开网站网站数据怎么更新
  • 淘宝客网站备案教程北京南站核酸检测点
  • 网站内部链接优化方法好的做网站的公司
  • iis网站服务器 建立出现问题代运营套餐价格表
  • ui网站开发交互设计考研太难了
  • 网站正在升级建设中代码网站建设及网络营销
  • 广州微网站建设服务交换链接的方法
  • 上传网站图片处理网站建设综合实训
  • 网站建设规划书应当包含哪些内容开公司要多少注册资金
  • 网站建设的常见技术有哪些平面设计的软件都有什么
  • 做的比较好的律师网站南京市城市建设档案馆网站
  • 注册网站刀具与钢材经营范围seo的中文是什么
  • 网站注册商是什么百度seo高级优化
  • 百度为什么打不开网页无法访问织梦做的网站好优化
  • 电影网站如何优化织梦
  • 九江本土专业网站建设网络策划书一般包括哪些内容
  • 专注七星彩网站开发建设银行哈尔滨分行网站
  • 关于做美食的网站网站建设需要多少钱小江
  • 盘龙区网站建设外包科技进步是国防强大的重要的保证
  • 理财网站开发文档网站案例上海
  • 盘锦注册公司益阳网站seo
  • 做编辑器的网站重庆网站推广优化软件业务