是不是 product_name 查询条件是中文的缘故?换个英文的试试

解决方案 »

  1.   

      <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 ............................
    你运行的和你贴出来的不是一个吧。
      

  2.   

    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和你输入的参数值,和类型!你说的记录不存在。
      

  3.   

    我是通过查询分析器对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语句~~~
      

  4.   

    注意“$”和“#”分别怎么用,你就知道了。
    凡是#的,都作为参数,用setObject方式,会自动在两头加单引号。而$方式的,则直接替换字符串。
    如果是字符,比如:product_name = 领带,就挂了。要product_name = '领带' 。
    楼主试试吧。
      

  5.   

    select没有设置resultClass="pojo对象"
    如果没有定义就用resultClass="map"
      

  6.   

    问题解决了,很晕,原来没写resultMap,不过倒是知道了#和$的用法,如果传进去的是字符串参数, product_name = #productName#和 product_name = '$productName$'写法是等价的。