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

有经验的郑州网站建设wordpress小米论坛主题

有经验的郑州网站建设,wordpress小米论坛主题,做网站什么价格,住建局网站官网核心配置 JavaBeanMapper.xml#xff08;sql映射#xff09; 作用 JavaBeanMapper.xml实现#xff1a; 用来干什么#xff1f; 定义Sql语句映射。相对照JDBC的实现#xff0c;是将原本的Sql代码提取出来#xff0c;最终根据映射关系执行Sql操作。 好处#xff1f; 解…核心配置 JavaBeanMapper.xmlsql映射 作用 JavaBeanMapper.xml实现 用来干什么 定义Sql语句映射。相对照JDBC的实现是将原本的Sql代码提取出来最终根据映射关系执行Sql操作。 好处 解耦mapper只关心定义Sql的映射关系与java代码分离更易维护。 如何使用 先来展示一个基本的mapper xml这里涉及到主要的几个标签元素 SelectInsertUpdateDeleteResultMapSqlCache ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespaceorg.example.daos.UserMapperresultMap iduserMap typeCustomerresult columnpwd propertypassword//resultMapselect idgetUserList resultMapuserMapSELECT * FROM mybatis.user/selectselect idgetUserListByRowBounds resultMapuserMapSELECT * FROM mybatis.user/select!-- 模糊查询1--!--select idgetUserListForFuzzyQuery resultTypeorg.example.pojo.UserSELECT * FROM mybatis.user where name like #{name}/select--!-- 模糊查询2 %--select idgetUserListForFuzzyQuery resultTypeorg.example.pojo.UserSELECT * FROM mybatis.user where name like %#{name}/select!-- 形参只有一个且为基本类型时parameterType可省略parameterTypeint --select idgetUserById resultTypeorg.example.pojo.UserSELECT * FROM mybatis.user where id #{id}/selectinsert idaddUser parameterTypeorg.example.pojo.UserINSERT INTO mybatis.user(id, name, pwd) values (#{id},#{name},#{pwd})/insertupdate idupdateUserByUser parameterTypeorg.example.pojo.UserUPDATE mybatis.user set name#{name}, pwd#{pwd} where id#{id}/updateupdate idupdateUserByMap parameterTypemapUPDATE mybatis.user set name#{userName}, pwd#{userPwd} where id#{userId}/updatedelete iddeleteUser parameterTypeintDELETE FROM mybatis.user where id#{id}/delete /mapper 具体的标签元素 Select 这里的重点是resultTyperesultMap的使用两者只能二选一 ResultType语句中返回结果的类全限定名或别名。一般是该sql映射方法的返回值类型。特殊的如果是集合类型则只需定义集合的泛型类型即可。ResultMap对外部 resultMap 的命名引用。一般用于处理复杂的映射结果查询比如多表查询一对多多对一 多对一查询 ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespaceorg.example.daos.StudentMapper!-- 多对一查询方式1Teacher再查一次:子查询相当于:select id, name, tid from student where tid (select id from teacher where id tid)--!--resultMap idStudentTeacher1 typeStudentid propertyid columnid/result columnname propertyname/association propertyteacher columntid selectgetTeacherById javaTypeTeacher//resultMapselect idgetStudentList resultMapStudentTeacher1select * from student/selectselect idgetTeacherById resultTypeTeacherselect * from teacher where id#{tid}/select--!-- 多对一查询方式2按照结果嵌套, 联表查询相当于select s.id sid, s.name sname, t.id tid, t.name tname from student s, teacher t where s.tid t.id--select idgetStudentList resultMapStudentTeacher2select s.id sid, s.name sname, t.id tid, t.name tname from student s, teacher t where s.tid t.id/selectresultMap idStudentTeacher2 typeStudentresult propertyid columnsid/result propertyname columnsname/association propertyteacher javaTypeTeacherid columnid propertytid/result propertyname columntname//association/resultMap/mapper一对多查询 ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespaceorg.example.daos.TeacherMapper!--一对多方式1联表查询 --select idgetTeacherById resultMapTeacherStudentselect t.id tid, t.name tname, s.id sid, s.name sname from teacher t, student s where t.id s.tid and t.id#{tid}/selectresultMap idTeacherStudent typeTeacherresult propertyid columntid/result propertyname columntname/collection propertystudentList ofTypeStudentresult propertyid columnsid/result propertyname columnsname/result propertytid columntid//collection/resultMap!--一对多方式2子查询 --select idgetTeacherById2 resultMapTeacherStudent2select * from teacher where id#{tid}/selectresultMap idTeacherStudent2 typeTeacherresult columnid propertyid/collection propertystudentList columnid ofTypeStudent selectgetStudentByTid//resultMapselect idgetStudentByTid resultTypeStudentselect * from student where tid#{tid}/select /mapperInsert涉及到自动生成主键id的设置(keyProperty, useGeneratedKeys)多行插入(foreach)UpdateDelete !-- 自动生成主键id -- insert idinsertAuthor useGeneratedKeystruekeyPropertyidinsert into Author (username,password,email,bio)values (#{username},#{password},#{email},#{bio}) /insert!-- 多行插入 -- insert idinsertAuthor useGeneratedKeystruekeyPropertyidinsert into Author (username, password, email, bio) valuesforeach itemitem collectionlist separator,(#{item.username}, #{item.password}, #{item.email}, #{item.bio})/foreach /insertupdate idupdateAuthorupdate Author setusername #{username},password #{password},email #{email},bio #{bio}where id #{id} /updatedelete iddeleteAuthordelete from Author where id #{id} /deleteSqlsql语句重用片段。也可动态赋值 sql idif_title_authorif testtitle! nullAND title #{title}/ifif testauthor ! nullAND author #{author}/if /sqlselect idqueryBlog1 parameterTypemapselect * from blog where 11include refidif_title_author/ /select!-- 动态赋值: ${include_target}, property -- sql idsomeincludefrominclude refid${include_target}/ /sql select idselect resultTypemapselectfield1, field2, field3include refidsomeincludeproperty nameprefix valueSome//include /select参数的定义 如果一个列允许使用 null 值并且会使用值为 null 的参数就必须要指定 JDBC 类型jdbcType #{average,javaTypedouble,jdbcTypeNUMERIC,typeHandlerMyTypeHandler,numericScale2}字符串替换: ${}方式不会被预编译转义可以通过这种方式指定某个字符串column而非对应的数值。但存在sql注入风险。 Select(select * from user where ${column} #{value}) User findByColumn(Param(column) String column, Param(value) String value);association collection collection 用于一对多association用于多对一。 association 联表查询 association propertyauthor columnblog_author_id javaTypeAuthorid propertyid columnauthor_id/result propertyusername columnauthor_username/ /associationassociation 子表查询 resultMap idblogResult typeBlogassociation propertyauthor columnauthor_id javaTypeAuthor selectselectAuthor/ /resultMapcollection子表查询 collection propertyposts columnid ofTypePost selectselectPostsForBlog/collection联表查询 resultMap idblogResult typeBlogid propertyid columnblog_id /result propertytitle columnblog_title/collection propertyposts ofTypePostid propertyid columnpost_id/result propertysubject columnpost_subject/result propertybody columnpost_body//collection /resultMapOfType collection propertyposts javaTypeArrayList columnid ofTypePost selectselectPostsForBlog/可以读作 “posts 是一个存储 Post 的 ArrayList 集合” 。且在一般情况下MyBatis 可以推断 javaType 属性因此并不需要填写。 缓存Cache 一级缓存默认开启。SqlSession级别的缓存也叫本地缓存二级缓存基于namespace级别的缓存针对mapper cache, LRU, FIFO开启二级缓存需要在对于mapper上加入标签元素Cache即可当会话sqlSession提交commit或关闭close时一级缓存的数据才会提交到二级缓存中缓存顺序当查询业务来到DAO层时 先查看二级缓存再查看一级缓存最后再查数据库 动态Sql解决在定义Sql映射时拼接sql语句where子句条件SET子句多条语句foreach的编写。参考链接 If, choose, foreach, trim 分页limit Select * from user limit startIndex, pageSizeRowBoundsselectList (String statement, Object parameter, RowBounds rowBounds)Mybatis PageHelper 注解开发 参考链接
http://www.w-s-a.com/news/727226/

相关文章:

  • 网站统计分析平台做企业礼品的网站
  • 做可视化图表的网站wordpress批量导入tag
  • txt怎么做网站网站的链接结构包括
  • 适合平面设计师的网站网络营销专员的就业前景
  • 好订单网服装加工接单谷歌seo网站推广怎么做
  • seo泛站群外贸网站建设团队
  • 网站免费维护建立网站国家城乡建设部投诉网站
  • 企业网站必须备案吗wordpress导入数据库依然无法链接
  • 浅谈高校网站群的建设网站不支持m.域名
  • 和平网站建设公司做实验教学视频的网站
  • 音乐网站源码带手机版WordPress菜单调用不出
  • 昆明网站设计都需要设计什么网络推广岗位职责和任职要求
  • 国外公司网站模板网站建设公司选择意见书
  • 如何创建一个网站卖东西郑州 网站建设公司
  • 石景山郑州阳网站建设南京网站搜索引擎优化
  • 一个网站需要哪些备案书店网站建设策划书总结
  • 网站建设的重点是什么注册网站空间
  • 网站公司企业宗旨我的网站 dedecms
  • 沧州网站优化做详情图的网站
  • 中国建设银行公积金网站wordpress表单 post
  • 找权重高的网站方法wordpress视频网站上传视频
  • 营销型网站架构师迁移wordpress500错误
  • 做网站还是博客由()承担
  • wordpress 导购站模板中国最新军事新闻直播83军
  • 公众号h5网站开发wordpress文章主图
  • ps怎么艺术字字体设计网站我想自己做网站
  • 北京做机柜空调的网站模板网站和插件
  • 手机购物网站模板wordpress添加分类文档
  • 网站开发知识网上怎么申请个人营业执照
  • 音乐网站建设费用营销策略都有哪些4p