如何给mybatis配置SQL语句

余人_ 2017-07-27 11:33:42
SELECT * FROM (SELECT * FROM WARNING_RECORD ORDER BY CREATE_TIME DESC )
WHERE ROWNUM <= 5

如题我向在mybatis中添加这样一条语句,怎么是实现?
...全文
167 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
月明星稀灬 2017-07-27
  • 打赏
  • 举报
回复
<?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.alphago.dao.UserDao" >
	<resultMap id="BaseResultMap" type="UserInfo" >
	    <id column="id" property="id" jdbcType="INTEGER" />
	    <result column="userName" property="userName" jdbcType="VARCHAR" />
	    <result column="password" property="password" jdbcType="VARCHAR" />
	    <result column="userEmail" property="userEmail" jdbcType="VARCHAR" />
	    <result column="telephone" property="telephone" jdbcType="VARCHAR" />
	    <result column="isEnable" property="isEnable" jdbcType="INTEGER" />
	    <result column="userLevel" property="userLevel" jdbcType="INTEGER" />
	</resultMap>

	<sql id="sqlwhere">
		<where>
			 1=1 
			<if test="id != null">
				and A.id = #{id}
			</if>
			<if test="userName != null && userName.length() > 0">
				and A.userName like  CONCAT(CONCAT('%','${userName}'),'%' )  
			</if>
			<if test="userEmail != null && userEmail.length() > 0">
				and A.userEmail like CONCAT(CONCAT('%','${userEmail}'),'%' ) 
			</if>
			<if test="telephone != null && telephone.length() > 0">
				and A.telephone like CONCAT(CONCAT('%','${telephone}'),'%' )
			</if>
			<if test="isEnable != null">
				and A.isEnable = #{isEnable}
			</if>
			<if test="userLevel != null">
				and A.userLevel = #{userLevel}
			</if>
		</where>
  	</sql>

	<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
		select * from sys_user A where A.id = #{id}
	</select>
</mapper>
myzhongw 2017-07-27
  • 打赏
  • 举报
回复
<select id='接口的方法名' resultType=‘返回的类’> SELECT * FROM (SELECT * FROM WARNING_RECORD ORDER BY CREATE_TIME DESC ) WHERE ROWNUM <= 5 </select>
余人_ 2017-07-27
  • 打赏
  • 举报
回复
<![CDATA[ SELECT <include refid="warningRecordColumns"/> FROM (SELECT <include refid="warningRecordColumns"/> FROM WARNING_RECORD ORDER BY CREATE_TIME DESC ) WHERE ROWNUM <= 5 ]]> include 这块怎么写呢?
一个帅逼 2017-07-27
  • 打赏
  • 举报
回复
<?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.test.zsj.dao.TestDao">
<select id="queryByTitleId" resultType="article" >
select  * from t_article where aritcle_id=#{0}
</select>

	</mapper>
自己看吧
李德胜1995 2017-07-27
  • 打赏
  • 举报
回复
余人_ 2017-07-27
  • 打赏
  • 举报
回复
引用 1 楼 wuli_genji 的回复:
在daomapping配置文件里写
我知道在那里面写,关键是怎么写
一个帅逼 2017-07-27
  • 打赏
  • 举报
回复
在daomapping配置文件里写

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧