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

相关文章:

  • 用dreamever如何建设网站企业门户网站建设方案怎么写
  • 网站及app开发网站建设内容存储
  • 网站建设外包手机移动端网站建设
  • 网站绑定ftp购买高仿手表网站
  • 广州门户网站建设wordpress游客登录
  • 商城网站建设费用crm管理系统软件哪家好
  • 溧水做网站网站关键词推广做自然排名
  • it 网站模板网站发布到互联网上的步骤
  • 网站维护指导域名注册查询阿里云
  • 建设中的网站备案期间做什做网站去哪里好
  • dw做的网站怎么发布福建省城乡建设官方网站
  • 自己做的网站可以有多个前端吗50强网站开发语言
  • 如何做网站产品图片网站的360快照怎么做
  • 云浮 网站建设受欢迎的网站建设平台
  • 网站设计管理方向西安专业网络推广平台
  • 怎么建立外贸网站免费申请httq网站?
  • 制作 网站曹鹏wordpress教程
  • 昆山市有没有做网站设计的物流专线做网站
  • 北京定制公交网站wordpress升级后等待
  • 网站品牌栏目建设优秀网站架构
  • dw网站怎么做点击图片放大微信网站开发流程
  • 视频网站X站H站搭建建设夜间直播平台排行榜前十名
  • 网站建设免费售后服务html中文网站作业
  • 上海市建设工程检测行业协会网站拼多多代运营一般多少钱
  • 如何做适合手机访问的网站安居客房产网
  • 做网站游戏的网站有哪些wordpress v2ex主题
  • 西安网站建设中企建站免费个人网站建设哪里好
  • 网站开发人员招募费用网站首页图片代码
  • 贵阳市做网站的公司农村建设网站
  • 山西网站建设报价单福田网站建设课程考试