mybatis分页+条件查询 条件不能有id字段?

u014380771 2014-05-23 04:46:37

当分页查询和条件查询一起使用时,查询的where语句下不能使用id字段,用了就查询不了!
...全文
383 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32300441 2015-12-31
  • 打赏
  • 举报
回复
同问 <select id="select" resultMap="TSysUserMap" > select * from t_sys_user <where> <if test="userId != null"> user_id = #{userId,jdbcType=INTEGER} </if> <if test="userName != null"> user_name = #{userName,jdbcType=INTEGER} </if> </where> <if test="Start!=null and rows!=null"> limit #{Start},#{rows} </if> </select> 条件分页无结果
u014380771 2014-05-23
  • 打赏
  • 举报
回复
引用 7 楼 wawy000 的回复:
我记得ibatis有个isnotnull 的标签吧,没必要搞得这么复杂吧。。 <isNotNull prepend="and" property="user_id"> user_id=#user_id# </isNotNull>
那是老版的了 而且我不是要问这个
wawy000 2014-05-23
  • 打赏
  • 举报
回复
我记得ibatis有个isnotnull 的标签吧,没必要搞得这么复杂吧。。 <isNotNull prepend="and" property="user_id"> user_id=#user_id# </isNotNull>
u014380771 2014-05-23
  • 打赏
  • 举报
回复
引用 5 楼 lgc8023 的回复:
<if test="user_id!=0 and user_id!=null"> and user_id=#{user_id} </if> user_id!=0应该这么些吧:user_id!='0'
user_id是integer类型的 我从id改成user_id之后是可以运行的
lgc8023 2014-05-23
  • 打赏
  • 举报
回复
<if test="user_id!=0 and user_id!=null"> and user_id=#{user_id} </if> user_id!=0应该这么些吧:user_id!='0'
u014380771 2014-05-23
  • 打赏
  • 举报
回复
引用 3 楼 xiaming08240316 的回复:
报什么错啊
没有报错,但是查询不到东西!但是语句在oracle里可以运行;我想问的是mybatis里的 new RowBounds 的分页查询是不是里面有id这个属性?还是其他原因?
木炎2019 2014-05-23
  • 打赏
  • 举报
回复
报什么错啊
u014380771 2014-05-23
  • 打赏
  • 举报
回复
引用 1 楼 u014380771 的回复:
<sql id="sel_sql">
		SELECT * FROM NEWS  
		<trim prefix="where" prefixOverrides="and">
			<if test="user_id!=0 and user_id!=null">
				and user_id=#{user_id}
			</if>
			<if test="title!='' and title!=null">
				and title like '%${title}%'
			</if>
			<if test="content!='' and content !=null">
				and content like '$%{content}%'
			</if>
			<if test="timeLine !=null and timeLine !=''">
				and createdate  #{timeLine}
			</if>
		</trim>
		ORDER BY CREATEDATE
	</sql>
开始的user_id 的字段名位id 结果就查询不到语句了= =!
u014380771 2014-05-23
  • 打赏
  • 举报
回复
<sql id="sel_sql">
		SELECT * FROM NEWS  
		<trim prefix="where" prefixOverrides="and">
			<if test="user_id!=0 and user_id!=null">
				and user_id=#{user_id}
			</if>
			<if test="title!='' and title!=null">
				and title like '%${title}%'
			</if>
			<if test="content!='' and content !=null">
				and content like '$%{content}%'
			</if>
			<if test="timeLine !=null and timeLine !=''">
				and createdate  #{timeLine}
			</if>
		</trim>
		ORDER BY CREATEDATE
	</sql>

67,513

社区成员

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

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