ibatis动态查询 是不是 product_name 查询条件是中文的缘故?换个英文的试试 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <select id="getOrdersBySelective" parameterClass="order"> select order_id, account_id, product_name, unit_price, quantity, days, total_money, delivery_date, is_box, booking_date, begin_date, order_date, order_status, re from orders <dynamic prepend="where"> <isNotNull prepend="and" property="accountId"> account_id = #accountId# </isNotNull> <isNotNull prepend="and" property="productName"> product_name = #productName# </isNotNull> <isNotNull prepend="and" property="totalMoney"> total_money = #totalMoney# </isNotNull> <isNotNull prepend="and" property="deliveryDate"> delivery_date = #deliveryDate# </isNotNull> <isNotNull prepend="and" property="bookingDate"> booking_date = #bookingDate# </isNotNull> <isNotNull prepend="and" property="beginDate"> begin_date = #beginDate# </isNotNull> <isNotNull prepend="and" property="orderDate"> order_date = #orderDate# </isNotNull> <isNotNull prepend="and" property="orderStatus"> order_status = #orderStatus# </isNotNull> </dynamic> </select> 你这个生成的sql是错的,你怎么可能运行?select order_id, account_id, product_name, unit_price, quantity, days, total_money, delivery_date, is_box, booking_date, begin_date, order_date, order_status, re from orders where and ............................你运行的和你贴出来的不是一个吧。 2008-11-06 16:17:58,593 DEBUG [java.sql.PreparedStatement] - {pstm-100007} PreparedStatement: select order_id, account_id, product_name, unit_price, quantity, days, total_money, delivery_date, is_box, booking_date, begin_date, order_date, order_status, re from orders where account_id = ? and product_name = ? 2008-11-06 16:17:58,593 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Parameters: [1, 领带] 2008-11-06 16:17:58,593 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Types: [java.lang.String, java.lang.String] 这也不能说明是有记录。上面打的只不过是生成的预编译sql和你输入的参数值,和类型!你说的记录不存在。 我是通过查询分析器对ibatis生成的SQL进行查询的,记录是有的,select order_id, account_id, product_name, unit_price, quantity, days, total_money, delivery_date, is_box, booking_date, begin_date, order_date, order_status, re from orders where account_id = 1 and product_name = '领带'以上就是在查询分析器中执行的SQL语句,有记录,不知道ibatis是如何把参数放进去的?对ibatis的源代码进行了跟踪,就是找不到SQL语句~~~ 注意“$”和“#”分别怎么用,你就知道了。凡是#的,都作为参数,用setObject方式,会自动在两头加单引号。而$方式的,则直接替换字符串。如果是字符,比如:product_name = 领带,就挂了。要product_name = '领带' 。楼主试试吧。 select没有设置resultClass="pojo对象"如果没有定义就用resultClass="map" 问题解决了,很晕,原来没写resultMap,不过倒是知道了#和$的用法,如果传进去的是字符串参数, product_name = #productName#和 product_name = '$productName$'写法是等价的。 jacorb的ssl问题 模糊搜索,返回结果字把搜索关键字替换成红色(如百度的搜索)。 如何实现? java能用流作为方法参数吗? 国企好还是外企好?(软件开发) 我照书打了一个JavaMail简单的发送邮件的代码,不知道怎么去运行成功,请高人指点! 学完ACCP后该怎么办??? 我只用来作J2EE。我为什么要装一个达5G的LINUX哪? 公司急招java高级程序员,要出一份面试考题,各位帮忙 使用openfire做群聊工具 国际化多语种内容系统的设计与实现? hibernate取出数据库对象不为空,但为什么列为空呢? Struts2输入校验显示问题
select order_id, account_id, product_name, unit_price, quantity, days, total_money,
delivery_date, is_box, booking_date, begin_date, order_date, order_status, re
from orders
<dynamic prepend="where">
<isNotNull prepend="and" property="accountId">
account_id = #accountId#
</isNotNull>
<isNotNull prepend="and" property="productName">
product_name = #productName#
</isNotNull>
<isNotNull prepend="and" property="totalMoney">
total_money = #totalMoney#
</isNotNull>
<isNotNull prepend="and" property="deliveryDate">
delivery_date = #deliveryDate#
</isNotNull>
<isNotNull prepend="and" property="bookingDate">
booking_date = #bookingDate#
</isNotNull>
<isNotNull prepend="and" property="beginDate">
begin_date = #beginDate#
</isNotNull>
<isNotNull prepend="and" property="orderDate">
order_date = #orderDate#
</isNotNull>
<isNotNull prepend="and" property="orderStatus">
order_status = #orderStatus#
</isNotNull>
</dynamic>
</select> 你这个生成的sql是错的,你怎么可能运行?
select order_id, account_id, product_name, unit_price, quantity, days, total_money,
delivery_date, is_box, booking_date, begin_date, order_date, order_status, re
from orders where and ............................
你运行的和你贴出来的不是一个吧。
2008-11-06 16:17:58,593 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Parameters: [1, 领带]
2008-11-06 16:17:58,593 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Types: [java.lang.String, java.lang.String]
这也不能说明是有记录。上面打的只不过是生成的预编译sql和你输入的参数值,和类型!你说的记录不存在。
select order_id, account_id, product_name, unit_price, quantity, days, total_money,
delivery_date, is_box, booking_date, begin_date, order_date, order_status, re
from orders
where account_id = 1 and product_name = '领带'
以上就是在查询分析器中执行的SQL语句,有记录,不知道ibatis是如何把参数放进去的?
对ibatis的源代码进行了跟踪,就是找不到SQL语句~~~
凡是#的,都作为参数,用setObject方式,会自动在两头加单引号。而$方式的,则直接替换字符串。
如果是字符,比如:product_name = 领带,就挂了。要product_name = '领带' 。
楼主试试吧。
如果没有定义就用resultClass="map"