今天遇到一个问题,就是写xml文件时,返回的顺序始终不一致,无论我sql语句写的如何好,前端接收到的数据都是乱的。终于,我发现到了醉翁亭记注音版原因。
原来我的查询返回resulttype = “map” , 也就是这个map, 打乱了顺序。
因为map 并不保证存入取出顺序一致, 因此,打乱顺序可想而知了。
resulttype = “map” 改为 resulttype=”java.util.linkedhashmap” 。
介绍:返回为linkedhashmap时,表中存储的null值并不会存入map中。
<?xml version="1.0" encoding="utf-8"?><!doctype mapper public "-//mybatis.org//dtd mapper 3.0//en" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.inspur.analysis.tool.ontology.linktype.dao.linktypemapper"> <resultmap type="com.inspur.analysis.tool.ontology.linktype.data.linktype" id="linktype"> <id property="linkuri" column="link_uri"/> <result property="urihash" column="uri_hash"/> <result property="batypeuri" column="ba_type_uri"/> <result property="linklabel" column="link_label"/> <result property="isasymmetrical" column="is_asymmetrical"/> <result property="alia" column="alia"/> <result property="pcname" column="p_c_name"/> <result property="pcalia" column="p_c_alia"/> <result property="cpname" column="c_p_name"/> <result property="cpalia" column="c_p_alia"/> <result property="detailiconuri" column="detail_icon_uri"/> <result property="detailicon" column="detail_icon"/> <result property="edgeiconuri" column="edge_icon_uri"/> <result property="edgeicon" column="edge_icon"/> <result property="issys" column="is_sys"/> <result property="note" column="note"/> <result property="creatorid" column="creator_id"/> <result property="createtime" column="create_time"/> <result property="editorid" column="editor_id"/> <result property="edittime" column="edit_time"/> <result property="scn" column="scn"/> </resultmap> <lect id="existlinktypeuri" parametertype="string" resultmap="linktype"> lect * from od_link_t杞人忧天原文ype where link_uri = #{linkuri} </lect> <lect id="isrootlinktype" parametertype="string" resulttype="int"> lect exists(lect link_uri from od_link_type progresd where link_uri=ba_type_uri and link_uri=#{linkuri}) </lect> <lect id="deleterootlinktype" parametertype="string"> delete from od_link_type where ba_type_uri=#{batypeuri} </lect> <lect id="getrootlinktypelist" resultmap="linktype"> lect * from od_link_type where link_uri = ba_type_uri </lect> <lect id="getalllinktypelistbyparent" parametertype="java.util.map" resultmap="linktype"> lect * from od_link_type <where> link_uri != ba_type_uri <if test="batypeuri != null"> and ba_type_uri=#{batypeuri} </if> </where> <if test="orderfield != null" > order by <choo> <when test="orderfield == 'linkuri'"> 鸿门宴课文 link_ur2020感动中国十大人物观后感i ${orderdir} </when> <when test="orderfield == 'linklabel'"> link_label ${orderdir} </when> <otherwi> ba_type_uri ${orderdir} </otherwi> </choo> </if> </lect> <lect id="getlinktypelistbycondition" parametertype="java.util.map" resultmap="linktype"> lect * from od_link_type <where> link_uri != ba_type_uri <if test="linkuri != null"> and link_uri like '%${linkuri}%' </if> <if test="linklabel != null"> and link_label like '%${linklabel}%' </if> <if test="batypeuri != null"> and ba_type_uri=#{batypeuri} </if> </where> <if test="orderfield != null" > order by <choo> <when test="orderfield == 'linkuri'"> link_uri ${orderdir} </when> <when test="orderfield == 'linklabel'"> link_label ${orderdir} </when> <otherwi> ba_type_uri ${orderdir} </otherwi> </choo> </if> </lect></mapper>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。
本文发布于:2023-04-04 20:57:01,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/51b40a08666705df4c3713d34dcdefaf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Mybatis如何按顺序查询出对应的数据字段.doc
本文 PDF 下载地址:Mybatis如何按顺序查询出对应的数据字段.pdf
留言与评论(共有 0 条评论) |