想请教一个ibatis查询的问题,本人刚学ibatis,请多指教
bue21 2012-08-05 05:26:10 各位GG.JJ们好:
最近小弟在学ibatis框架,自己在写一个论坛的web项目,这段时间遇到了个问题,辗转反侧的折磨了我很久,在实在没有独自解决的办法下,只有请求大家的力量了.谢谢各位先
来说一下问题吧, 我现在在用ibatis查询的时候,查一张表的记录,在xml中配置如下:
<typeAlias alias="topVO" type="com.xxx.vo.TopicVO"/>
<resultMap class="topVO" id="topMap">
<result property="topId" column="TOP_ID"/>
<result property="topSid" column="TOP_SID"/>
<result property="topUid" column="TOP_UID"/>
<result property="topName" column="TOP_NAME"/>
<result property="topText" column="TOP_TEXT"/>
<result property="topTime" column="TOP_TIME"/>
<result property="topCountclick" column="TOP_COUNTCLICK"/>
<result property="topReplacecount" column="top_replycount"/>
<result property="topPy" column="TOP_PY"/>
<result property="topBiaoqing" column="TOP_BIAOQING"/>
<result property="topFlag" column="TOP_FLAG"/>
<result property="isDelete" column="is_delete"/>
<result property="createDate" column="create_date"/>
<result property="createBy" column="create_by"/>
<result property="lastUpdateBy" column="last_update"/>
<result property="lastUpdateDate" column="lasg_logindate"/>
</resultMap>
当我执行以下这条sql:
<select id="getTopinfoById" parameterClass="java.lang.String" resultMap="topMap">
select t.top_id,
t.top_sid,
t.top_uid,
t.top_name,
t.top_text,
t.top_time,
t.top_countclick,
t.top_replycount,
t.top_biaoqing,
t.top_flag,
t.create_date
from topic t where t.is_delete=1 and t.top_id=#sid#
</select>
出现列名无效的异常,
javax.servlet.ServletException: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/sie/config/bbs.xml.
--- The error occurred while applying a result map.
--- Check the bbs.topMap.
--- Check the result mapping for the 'topPy' property.
--- Cause: java.sql.SQLException: 列名无效
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.sie.filter.Chinese.doFilter(Chinese.java:26)
但是当我执行这条sql的时候却能成功:
<select id="showTopic" parameterClass="java.lang.String" resultMap="topMap">
select top_id,
t.top_sid,
t.top_uid,
t.top_name,
t.top_text,
t.top_time,
t.top_py,
t.top_countclick,
t.top_replycount,
t.top_biaoqing,
t.top_flag,
t.is_delete,
t.create_date,
t.create_by,
t.last_update,
t.lasg_logindate
from topic t , sessioninfo s where t.top_sid = #sid# and t.is_delete=1 and t.top_sid = s.session_id
</select>
2条sql的区别在于查询的字段不同,以及查询条件不同.当我将下面这条查询的列名复制到与第一条报错的sql中时,却又不报错,想请问,这是需要配置什么才能不出现这种情况呢?
小弟愚昧.还想请大家能帮帮我,或者是能够说出你们的想法. 谢谢大家了