代码拉取完成,页面将自动刷新
在生成的mapper中,select操作对分页进行优化时使用了inner join,这里如果使用非连接属性进行排序,如果驱动表是左表,那么排序就会失效。
<select id="selectStorageInfo" parameterType="com.common.Assist" resultMap="result_StoreStorageInfo_Map">
select
<if test="distinct !=null">${distinct}</if>
<choose>
<when test="resultColumn!=null">${resultColumn}</when>
<otherwise>
<include refid="store_storage_info_Column" />
</otherwise>
</choose>
from store_storage_info
<if test="require!=null">
<include refid="assist" />
</if>
<if test="order !=null">${order}</if>
<choose>
<when test="startRow !=null and rowSize !=null">LIMIT #{startRow},#{rowSize} </when>
<when test="rowSize !=null">LIMIT #{rowSize}</when>
</choose>
</select>
原谅我看了几遍还是没有看明白你的意思,只指生成的语句错误还是别的,我应该怎么做呢,因为这里并没有表连接
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
是我表述的太抽象了,我再具体一点:
<select id="selectStorageInfo" parameterType="com.common.Assist" resultMap="result_StoreStorageInfo_Map">
select
<if test="distinct !=null">${distinct}</if>
<choose>
<when test="resultColumn!=null">${resultColumn}</when>
<otherwise>
<include refid="store_storage_info_Column" />
</otherwise>
</choose>
from store_storage_info
<if test="require!=null">
<include refid="assist" />
</if>
<if test="order !=null">${order}</if>
<choose>
<when test="startRow !=null and rowSize !=null">LIMIT #{startRow},#{rowSize} </when>
<when test="rowSize !=null">LIMIT #{rowSize}</when>
</choose>
</select>
表中有一个字段是update_time,查询时根据update_time desc排序
这个xml转换成sql以后是:
select table.id, table.foreignId, table.update_time
from
table
inner join
(select id from table where foreignId = 123 order by update_time desc limit 0,10)
as tmp on table.id = tmp.id
通过这条sql进行查询时,子查询中的结果是根据update_time进行排序的,而inner join后排序的方式却不确定了,如果是按左边的table表作为驱动表则是按照table的默认方式进行排序,如果是以tmp临时表为驱动则是我们所期望的按照update_time来排序。我这里插入了5条数据,通过以上sql查询后的结果如下:
查询结果并没有按照update_time desc进行排序。
@zhuyuheng 正常来说inner join 里面排序了外面就排序了,如果不起作用的话你有两种方式可以处理,
1: 这个inner join是用来优化数据多时分页优化的,如果你认为没有必要可以在模板中取消这个inner join
2: 外面也加多一个order
登录 后才可以发表评论