Mybatis使用distinct問題及處理
Mybatis使用distinct問題
使用插件自動(dòng)生成sql
具體如下:
<resultMap id="versioncodeResult" type="java.lang.String" >
<result column="code" property="code" jdbcType="VARCHAR" />
</resultMap>
<select id="selectVersionCodeByParam" parameterType="com.entity.OdpsrequesttoidbtableParam" resultMap="versioncodeResult">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
versioncode as code
<include refid="Base_Column_List" />
from odpsrequesttoidbtable
<if test="_parameter != null">
<include refid="Param_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="page">
limit #{pageIndex},#{pageSize}
</if>
</select>
始終查詢不到我想要的結(jié)果
| 序號(hào) | code |
|---|---|
| 1 | 266 |
| 2 | 267 |
查看具體生成的sql發(fā)現(xiàn)
少去掉了一行
### SQL: select distinct versioncode as code id, gmt_create, gmt_modified, apiname, pkey, versioncode, appkey from odpsrequesttoidbtable WHERE ( appkey = ? )
修復(fù)后的sql如下
去掉"Base_Column_List" :
<select id="selectVersionCodeByParam" parameterType="com.entity.OdpsrequesttoidbtableParam" resultMap="versioncodeResult">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
versioncode as code
from odpsrequesttoidbtable
<if test="_parameter != null">
<include refid="Param_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="page">
limit #{pageIndex},#{pageSize}
</if>
</select>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解SpringBoot時(shí)間參數(shù)處理完整解決方案
這篇文章主要介紹了詳解SpringBoot時(shí)間參數(shù)處理完整解決方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
詳解SpringBoot簡(jiǎn)化配置分析總結(jié)
這篇文章主要介紹了詳解SpringBoot簡(jiǎn)化配置分析總結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(14)
下面小編就為大家?guī)硪黄狫ava基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望可以幫到你2021-07-07
SpringBoot集成Mybatis-plus并實(shí)現(xiàn)自動(dòng)生成相關(guān)文件的示例代碼
Mybatis-Plus是一個(gè)優(yōu)秀的Mybatis增強(qiáng)工具,目前更新到3.1.1,本文通過示例代碼給大家介紹SpringBoot集成Mybatis-plus并實(shí)現(xiàn)自動(dòng)生成相關(guān)文件的問題,感興趣的朋友跟隨小編一起看看吧2021-12-12
Java經(jīng)典設(shè)計(jì)模式之裝飾器模式解析
這篇文章主要介紹了Java經(jīng)典設(shè)計(jì)模式之裝飾器模式解析,裝飾器模式主要解決繼承關(guān)系過于復(fù)雜的問題,通過組合來替代繼承,指在不改變現(xiàn)有對(duì)象結(jié)構(gòu)的情況下,動(dòng)態(tài)地給該對(duì)象增加一些職責(zé)(即增加其額外功能)的模式,需要的朋友可以參考下2023-08-08
Java在并發(fā)環(huán)境中SimpleDateFormat多種解決方案
這篇文章主要介紹了Java在并發(fā)環(huán)境中SimpleDateFormat多種解決方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
MyBatis Plus插件機(jī)制與執(zhí)行流程原理分析詳解
這篇文章主要介紹了MyBatis Plus插件機(jī)制與執(zhí)行流程原理分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09

