第一种的xml配置根据最新的插入时间
<select id="selectLast" resultMap="BaseResultMap" parameterType="java.lang.String">
SELECT
*
from 表名
where createtime=(select max(createtime) from 表名 where
字段名=#{参数名,jdbcType=VARCHAR} )
</select>
第二种的xml配置根据ownum
select id="selectLast" resultMap="BaseResultMap" parameterType="java.lang.String">
select t.*,rownum from
(select * from 表名 where 字段名=#{参数名,jdbcType=VARCHAR}
order by createtime desc)t where rownum=1
</select>
不足之处请大家评论指出。
本文介绍了两种在MyBatis中查询最新数据的方法:一种是通过最新的插入时间,另一种是利用ownum字段。欢迎读者对不足之处进行评论交流。
1万+

被折叠的 条评论
为什么被折叠?



