如下ibatis-news.xml:
   <select id="queryNews" parameterClass="news" resultClass="news">                                     
select chr_id,title,ctime,htis,type,image  from news                                                                            
 <dynamic prepend="WHERE">                                                                                  
<isNotEmpty prepend="" property="chr_id">
    <isNotEqual compareValue="" prepend="and" property="chr_id">
      chr_id=#chr_id#
    </isNotEqual>
</isNotEmpty>
<isNotEmpty prepend="" property="title">
    <isNotEqual compareValue="" prepend="and" property="title">
      title=#title#
    </isNotEqual>
</isNotEmpty>
<isNotEmpty prepend="" property="ctime">
    <isNotEqual compareValue="" prepend="and" property="ctime">
      ctime=#ctime#
    </isNotEqual>
</isNotEmpty>
<isNotEmpty prepend="" property="htis">
    <isNotEqual compareValue="" prepend="and" property="htis">
      htis=#htis#
    </isNotEqual>
</isNotEmpty>
<isNotEmpty prepend="" property="type">
    <isNotEqual compareValue=""  prepend="and" property="type">
      type=#type#
    </isNotEqual>
</isNotEmpty>
<isNotEmpty prepend="" property="image">
    <isNotEqual compareValue="" prepend="and" property="image">
      image=#image#
    </isNotEqual>
</isNotEmpty>
   </dynamic>                                                                                                 
</select> 
这样动态拼接一个语句,后来发现
加入 type是 int类型的。
现在在action中来根据 type做查询。type是int类型:
回报如下错误:
java.lang.NumberFormatException: For input string: ""
在页面看到如下信息:
javax.servlet.ServletException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
The error occurred in org/zwck/business/news/ibatis-news.xml. 这个怎么办 是不是因为 type是int类型的而出错了。
我试过任何String了类型的不会错,也就是说如果 type是String类型的那就不会错。                                        

解决方案 »

  1.   

    那就将type在方法中转换成String类型的传过来 不就行了么
      

  2.   

    compareValue=""这句话应该是把比较的类型定义为String 了吧,所以会报错.<isNotEmpty prepend="" property="type">
      <isNotEqual compareValue="" prepend="and" property="type">
      type=#type#
      </isNotEqual>
    </isNotEmpty>
    LZ有必要这么写嘛,不为空(或NULL)且不等空,直接
    <isNotEmpty prepend="" property="type">
      type=#type#
    </isNotEmpty>
    不就行了
      

  3.   

    <isNotEmpty prepend="" property="type">
      type=#type#
    </isNotEmpty>
    这么写就没有那个问题了
      

  4.   

    int型数据在为空的情况下默认为0,其实你可以再输入数据之前做一个判断,使其不为空,确保数据格式正确
      

  5.   

    就是type不为空才会抱那个错误,如果为空不会有那个错误。
      

  6.   

    我一般是转换为integer 类型的