论坛首页 Java企业应用论坛

请教两个iBatis问题

浏览 9730 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-10-11  
<select id="getCount" resultClass="int" parameterClass="string">
		<![CDATA[
			select count(*); from STATREPORTPARAMVALUE
			where #value#
		]]>
	</select>


上面的写法对不对,主要有两个疑惑。
1、能不能返回int型的,如果能的话返回的是int还是Integer;
2、#value#是指我的查询条件,这是事先拼好的,把它作为一个字符串传进来,可不可以?

谢谢!
   发表时间:2005-10-11  
1、返回的是Integer
2、value是条件对象的属性
0 请登录后投票
   发表时间:2005-10-11  
我就是想在Java里面把查询条件拼好,然后传进去,这样程序就可以更加灵活一点,不知道可不可以。
0 请登录后投票
   发表时间:2005-10-11  
可以考虑使用iBATIS的动态SQL生成功能
0 请登录后投票
   发表时间:2005-10-12  
<select id="getCount" resultClass="int" parameterClass="string">
                <![CDATA[
                        select count(*); from STATREPORTPARAMVALUE
                        where $value$
                ]]>
        </select>
0 请登录后投票
   发表时间:2005-10-17  
1。int 是ibatis的关键字,是代表Int型!
2。可以传参数进去
0 请登录后投票
   发表时间:2005-10-17  
1.iBatis传入或者返回的都是对象。在sqlMap的xml文件中int/string只是Integer/String的别名,你要可以在它的技术文档到找到;
2.你写的sql有问题 where #value# 应该是where colume=$value$

desertman 写道
<select id="getCount" resultClass="int" parameterClass="string">
		<![CDATA[
			select count(*); from STATREPORTPARAMVALUE
			where #value#
		]]>
	</select>


上面的写法对不对,主要有两个疑惑。
1、能不能返回int型的,如果能的话返回的是int还是Integer;
2、#value#是指我的查询条件,这是事先拼好的,把它作为一个字符串传进来,可不可以?

谢谢!
0 请登录后投票
   发表时间:2005-10-19  
我觉得上面各位好像对#value#和$value$的区别不太清楚,注明一下#value#用的是占位符号,类似preparestatement的?,$value$是直接把sql替换改变了,
eg:
<select id="getCount" resultClass="int" parameterClass="string">
                <![CDATA[
                        select count(*); from STATREPORTPARAMVALUE
                        where $value$
                ]]>
        </select> 

这样你传入的参数可以是 name='rtm' 这样的条件,极端一点,
<select id="getCount" resultClass="int" parameterClass="string">
                <![CDATA[
                         $value$
                ]]>
        </select> 

如果用#value#的形式,就得用
<select id="getCount" resultClass="int" parameterClass="string">
                <![CDATA[
                        select count(*); from STATREPORTPARAMVALUE
                        where name=#value#
                ]]>
        </select> 

这样得写法了,上面这种写法类似
<select id="getCount" resultClass="int" parameterClass="parametermap">
                <![CDATA[
                        select count(*); from STATREPORTPARAMVALUE
                        where name=?
                ]]>
        </select> 

,但后面用?得写法如果传入值为null不会出错,#value#得写法传入null会出错,功能上两者差不多。详细请查看ibatis文档,里面有完整说明。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics