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

网站建设视频 备份 反代成功的品牌推广案例分析

网站建设视频 备份 反代,成功的品牌推广案例分析,网页设计素材模版,简约 网站模板这里先总结一下 association 存在的问题。 一、内嵌查询时存在报错Id找不到及内存溢出隐患 二、一对多关系数据重复问题 三、多层嵌套内层 association 查询结果为null 或 非预期的值 一、内嵌查询时存在报错Id找不到及内存溢出隐患 参考: https://www.lmlphp.co…

这里先总结一下 association 存在的问题。

一、内嵌查询时存在报错Id找不到及内存溢出隐患
二、一对多关系数据重复问题
三、多层嵌套内层 association 查询结果为null 或 非预期的值

一、内嵌查询时存在报错Id找不到及内存溢出隐患

参考: https://www.lmlphp.com/user/57996/article/item/1356741/
错误示例:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.lizhou.dao.StudentDao"><resultMap type="Student" id="studentResult"><id property="id" column="id"/><association property="grade" column="gradeId" select="com.lizhou.dao.GradeDao.getGrade"></association></resultMap><select id="getStudent" resultMap="studentResult">SELECT * FROM student<where><if test="id != null">AND id=#{id}</if></where></select></mapper> 

报错:Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.Integer’

正确示例:

<mapper namespace="com.lizhou.dao.GradeDao"><resultMap type="Grade" id="gradeResult"><id property="id" column="id"/></resultMap><select id="getGrade" parameterType="Grade" resultMap="gradeResult">SELECT * FROM grade WHERE id=#{id}</select></mapper> 

内存溢出隐患示例

错误示例:
StudentMapper.xml:

<mapper namespace="com.lizhou.dao.StudentDao"><resultMap type="Student" id="studentResult"><id property="id" column="id"/><association property="grade" column="gradeId" select="com.lizhou.dao.GradeDao.getGrade"></association></resultMap><select id="getStudent" resultMap="studentResult">SELECT * FROM student WHERE gradeId=#{gradeId}</select></mapper> 

GradeMapper.xml:

<mapper namespace="com.lizhou.dao.GradeDao"><resultMap type="Grade" id="gradeResult"><id property="id" column="id"/><collection property="studentList" column="id" ofType="Student" select="com.lizhou.dao.StudentDao.getStudent"></collection></resultMap><select id="getGrade" parameterType="Grade" resultMap="gradeResult">SELECT * FROM grade WHERE id=#{id}</select></mapper> 

解决方式:
分离写,分段查询

二、一对多关系数据重复问题

参考:https://blog.csdn.net/wuyezhiyu/article/details/81364974

 <resultMap id="commissionRec" type="CommissionRec" ><result property="sourceName" column="cmr_sourceName"/><result property="totalMoney" column="cmr_totalMoney"/><result property="totalCard" column="cmr_totalCard"/><result property="totalCommission" column="cmr_totalCommission"/><result property="commissionTimes" column="cmr_commissionTimes"/><result property="isProvided" column="cmr_isProvided"/><result property="userInfo.userId" column="us_userId"/><result property="userInfo.userName" column="us_userName"/><association property="memberCard" resultMap="memberCardTemplate" /> <!-- <association property="userInfo" resultMap="userInfo" /> --></resultMap>
 <resultMap id="userInfo" type="cn.sstech.member.marketing.model.base.BaseUserInfo" ><id property="userId" column="us_userId"/><result property="userName" column="us_userName"/></resultMap>

在这里插入图片描述
如上图所示查询结果中,第一条和第二条只有us_userId是不重复的,而剩下的字段都被注入到CommissionRec对象中。这时

1.用association注入userInfo mybatis会因为数据一样而将前两条数据合为一个CommissionRec对象,us_userId则随便调一个注入到userInfo对象中

2.用 <result property=“userInfo.userId” column=“us_userId”/> 这种制定具体字段名的方式注入,mybatis会因为记录数据有所不同而将前两条数据设为2个CommissionRec对象.

三、多层嵌套内层 association 查询结果为null 或 非预期

非预期

本人遇到的就是这个问题
以组织机构树的单张表为例,一般存的有ID及pre_id父级ID,当内嵌查询时,由于父级ID存在多条记录,导致查询结果并非预期

多层嵌套查询结果为null

参考:https://www.zhuxianfei.com/java/57394.html
错误示例:

<resultMap id="BaseResultMap" type="a.b.c.d.e"><id column="id" property="id" /><result property="workTime" column="work_time" /><result property="model" column="model" /><result property="status" column="status" /><association property="interfaceUpstream" javaType="interfaceUpstream" columnPrefix="ui_"><id column="id" property="id" /><result property="interfaceName" column="interface_name" /><result property="interfaceType" column="interface_type" /><result property="frequency" column="frequency" /><result property="address" column="address" /><result property="templateOrSql" column="template_or_sql" /><result property="status" column="status" /><association property="systemInfo" javaType="SystemInfo" columnPrefix="sys_"><id column="id" property="id"/><result property="systemName" column="system_name"/><result property="systemNameEN" column="system_name_en"/><result property="belong" column="belong"/><result property="status" column="status"/></association><association property="serverInfo" javaType="ServerInfo" columnPrefix="ser_"><id column="id" property="id"/><result property="ftpIp" column="ftp_ip"/><result property="ftpPort" column="ftp_port"/><result property="ftpAccount" column="ftp_account"/><result property="ftpPassword" column="ftp_password"/></association></association></resultMap>
<sql id="base_select">SELECTii.Id,ii.model,ii.status,ii.work_time,ui.id AS ui_id,ui.interface_name AS ui_interface_name,ui.interface_type AS ui_interface_type,ui.frequency AS ui_frequency,ui.address AS ui_address,ui.template_or_sql AS ui_template_or_sql,ui.status AS ui_status,sys.id AS sys_id,sys.system_name AS sys_system_name,sys.system_name_en AS sys_system_name_en,sys.belong AS sys_belong,sys.status AS sys_status,ser.id AS ser_id,ser.ftp_ip AS ser_ftp_ip,ser.ftp_port AS ser_ftp_port,ser.ftp_account AS ser_ftp_account,ser.ftp_password AS ser_ftp_password</sql>

结果: 内层的association查询的结果一直为null

原因是association在进行多层嵌套时,mybatis会将外层association的columnPrefix值与内层的进行并合,

如外层columnPrefix值位ui_, 内层为sys_, 那么在SQL中就不能这样 sys.id AS sys_id 了,需要将ui_前缀加上,变成 sys.id AS ui_sys_id ,这样mybatis在匹配的时候才会将数据映射到对应association上

正确示例:

SELECTii.Id,ii.model,ii.status,ii.work_time,ui.id AS ui_id,ui.interface_name AS ui_interface_name,ui.interface_type AS ui_interface_type,ui.frequency AS ui_frequency,ui.address AS ui_address,ui.template_or_sql AS ui_template_or_sql,ui.status AS ui_status,sys.id AS ui_sys_id,sys.system_name AS ui_sys_system_name,sys.system_name_en AS ui_sys_system_name_en,sys.belong AS ui_sys_belong,sys.status AS ui_sys_status,ser.id AS ui_ser_id,ser.ftp_ip AS ui_ser_ftp_ip,ser.ftp_port AS ui_ser_ftp_port,ser.ftp_account AS ui_ser_ftp_account,ser.ftp_password AS ui_ser_ftp_password

总结

1、能不用就别用
2、如果用,请务必指定对应的字段或id
3、多层嵌套时请注意前缀的使用
4、内嵌sql避免递归


文章转载自:
http://dinncoanarchy.ydfr.cn
http://dinncoshaddup.ydfr.cn
http://dinncoprepossessing.ydfr.cn
http://dinncoorthogonality.ydfr.cn
http://dinncosuccession.ydfr.cn
http://dinncocasquet.ydfr.cn
http://dinncopuck.ydfr.cn
http://dinncotaw.ydfr.cn
http://dinncocriminatory.ydfr.cn
http://dinncoloxodont.ydfr.cn
http://dinncomonasterial.ydfr.cn
http://dinncofurry.ydfr.cn
http://dinncobetise.ydfr.cn
http://dinncoinswinger.ydfr.cn
http://dinncomindy.ydfr.cn
http://dinncohelpless.ydfr.cn
http://dinncoresuscitation.ydfr.cn
http://dinncoearthquake.ydfr.cn
http://dinncotransplanter.ydfr.cn
http://dinncounimpressive.ydfr.cn
http://dinncofractional.ydfr.cn
http://dinncolister.ydfr.cn
http://dinncotrainer.ydfr.cn
http://dinncoboathook.ydfr.cn
http://dinncoshopworn.ydfr.cn
http://dinncoclannishly.ydfr.cn
http://dinncochenar.ydfr.cn
http://dinncooud.ydfr.cn
http://dinncounreconstructed.ydfr.cn
http://dinncotrinal.ydfr.cn
http://dinncomephistophelean.ydfr.cn
http://dinncogazebo.ydfr.cn
http://dinncophotographica.ydfr.cn
http://dinncoeastern.ydfr.cn
http://dinncothermojunction.ydfr.cn
http://dinncofraternize.ydfr.cn
http://dinncosubtility.ydfr.cn
http://dinncopurview.ydfr.cn
http://dinncoroumansh.ydfr.cn
http://dinncohabatsu.ydfr.cn
http://dinncospectrally.ydfr.cn
http://dinncoarginine.ydfr.cn
http://dinncophotoinduction.ydfr.cn
http://dinncojactation.ydfr.cn
http://dinncovoiceprint.ydfr.cn
http://dinncolubricator.ydfr.cn
http://dinncohurdle.ydfr.cn
http://dinncoprocrypsis.ydfr.cn
http://dinncopyonephritis.ydfr.cn
http://dinncomonorheme.ydfr.cn
http://dinncohornswoggle.ydfr.cn
http://dinncoplunger.ydfr.cn
http://dinncocarrie.ydfr.cn
http://dinncokottbus.ydfr.cn
http://dinncomaradi.ydfr.cn
http://dinncoyh.ydfr.cn
http://dinncocad.ydfr.cn
http://dinncouncurable.ydfr.cn
http://dinncoputrefaction.ydfr.cn
http://dinncogeraniaceous.ydfr.cn
http://dinncoapaprthotel.ydfr.cn
http://dinncocharman.ydfr.cn
http://dinncotexian.ydfr.cn
http://dinncoinlayer.ydfr.cn
http://dinncomucinogen.ydfr.cn
http://dinncosciomachy.ydfr.cn
http://dinncomelomane.ydfr.cn
http://dinncowrithen.ydfr.cn
http://dinncocurare.ydfr.cn
http://dinncounrazored.ydfr.cn
http://dinncomisshapen.ydfr.cn
http://dinncoviet.ydfr.cn
http://dinncoloosen.ydfr.cn
http://dinncoeffluvial.ydfr.cn
http://dinncodis.ydfr.cn
http://dinncosx.ydfr.cn
http://dinncocalcspar.ydfr.cn
http://dinncofornical.ydfr.cn
http://dinncosquirmy.ydfr.cn
http://dinncoleprosery.ydfr.cn
http://dinncostannary.ydfr.cn
http://dinncoestaminet.ydfr.cn
http://dinncofrostwork.ydfr.cn
http://dinncoelectrician.ydfr.cn
http://dinncologomachy.ydfr.cn
http://dinncoinhere.ydfr.cn
http://dinncofont.ydfr.cn
http://dinncoanzuk.ydfr.cn
http://dinncosinicism.ydfr.cn
http://dinncosubofficer.ydfr.cn
http://dinncopistole.ydfr.cn
http://dinncoicon.ydfr.cn
http://dinncodrury.ydfr.cn
http://dinncochawbacon.ydfr.cn
http://dinncoperibolos.ydfr.cn
http://dinncoaccessibility.ydfr.cn
http://dinncochess.ydfr.cn
http://dinncomaidservant.ydfr.cn
http://dinncoepyllion.ydfr.cn
http://dinncokitchenet.ydfr.cn
http://www.dinnco.com/news/135057.html

相关文章:

  • 自己做电视视频网站吗国际机票搜索量大涨
  • 大沥网站制作安徽网站推广公司
  • 网站开发和网页设计的区别seo入门培训学校
  • 免费的网站推广怎么做效果好营销策略怎么写
  • 做ppt的网站兼职营销网站有哪些
  • 小型网站设计及建设论文关键词排名查询工具有哪些
  • 广州网站制作网站推广软件下载
  • 最好用的网站推广经验万网域名管理入口
  • 网站建设 主要学是么国内新闻最近新闻今天
  • 注册网站的步骤百度的排名规则详解
  • 站长平台社区西安排名seo公司
  • 自学it做网站汕头seo收费
  • 做网站公司排名全渠道营销案例
  • 做网站公司怎么做企业查询系统官网
  • 黑红网站模板安徽网站关键词优化
  • 网站左侧的导航是怎么做的手机百度识图网页版入口
  • 哈尔滨建站seo技术 快速网站排名
  • 手机开发者网站搜易网托管模式的特点
  • 好看的网站模板今日百度小说排行榜风云榜
  • wordpress怎样恢复数据库常州seo博客
  • 网站设计学什么专业西安网站建设哪家好
  • 一个网站怎么做网站收录什么意思
  • 网站设计团队介绍找客户资源的软件免费的
  • 网站设计排名网站西安企业做网站
  • 网站建设与维护实训总结百度一下首页极简版
  • 网站开发需要的知识网站建设一般多少钱
  • 无忧网站建设服务网站宣传推广方案
  • 扬中市做网站适合seo的网站
  • 网站开发和软件开发区别成都专门做网络推广的公司
  • 营销网站制作教程seo网站排名优化快速排