ibatis 动态SQL问题

lkt19911025 2015-10-20 09:37:41
<select id="texselecttimulist" parameterClass="strsql" resultClass="strsql">
select * form bs_timu_tab
<dynamic prepend="where">
<isNotEmpty prepend="and" property="jiaoshi">
jiaoshihao=#jiaoshi#
</isNotEmpty>
<isNotEqual prepend="and" property="nian" compareValue="0">
nian=#nian#
</isNotEqual>
<isNotEqual prepend="and" property="bei4" compareValue="0">
bei4 like "%"+#bei4#+"%"
</isNotEqual>
<isNotEmpty prepend="and" property="timu">
timu like "%"+#timu#+"%"
</isNotEmpty>
</dynamic>

</select>

这是sql 配置 但是执行后报错
org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the texselecttimulist-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'form bs_timu_tab where jiaoshi='091201077' and nian='' at line 1

大神门这是为什么谢谢

...全文
185 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
引用 8 楼 rui888 的回复:
你是不是说. 错误是 nian=#nian# 这里是有值的 但是 提示错误 是空的 nian=''
找到 错误了 from 关键字写错了 谢谢
tony4geek 2015-10-21
  • 打赏
  • 举报
回复
你是不是说. 错误是 nian=#nian# 这里是有值的 但是 提示错误 是空的 nian=''
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
找到错误了 啊 气死我了 from 写错了 写成form了 40分 加分 到80分了 来一个 讲一个好笑的笑话 就结帖
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
sql 语句 select * 这些都没有了 为什么呢 大神帮帮忙啊 着急啊
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
我把 nian属性的判断后面的代码全都删掉了

<sql id="sql_select">  
        select *  
    </sql> 
<sql id="sql_where">
		form bs_timu_tab
		<dynamic prepend="where">
			<isNotEmpty prepend="BOGUS" property="jiaoshihao">
				jiaoshihao=#jiaoshihao#
			</isNotEmpty>
			
		</dynamic>
	</sql>
org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map. --- Check the texselecttimulist-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'form bs_timu_tab where jiaoshihao='091201077'' at line 1 还是报错 错误提示的sql语句 我发现 没有select *
tony4geek 2015-10-21
  • 打赏
  • 举报
回复
那么你先不判断 compareValue="0" 直接改 <isNotEmpty prepend="and" property="jiaoshi"> jiaoshihao=#jiaoshi# </isNotEmpty> 这样的看看.
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
<isNotEqual prepend="and" property="nian" compareValue="0"> nian=#nian# </isNotEqual> 你这个不先判断为空吗?
需要先判断 空 才能判断相等吗??? 年这个属性的值 是不为空的 控制台可以打印出来值
tony4geek 2015-10-21
  • 打赏
  • 举报
回复
<isNotEqual prepend="and" property="nian" compareValue="0"> nian=#nian# </isNotEqual> 你这个不先判断为空吗?
lkt19911025 2015-10-21
  • 打赏
  • 举报
回复
nian=#nian# 这里是有值的 但是 提示错误 是空的 nian='' 有没有人在 帮个忙谢谢

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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