iBatis sqlmap配置问题
刚学习使用iBatis,配置了一个文件login.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="login">
<typeAlias alias="MenuItem" type="com.newland.gxbc.dto.MenuItem" />
<!-- 菜单树 -->
<select id="listMenuTree" parameterClass="String" resultClass="MenuItem">
<![CDATA[
SELECT menu_id menuId, menu_up_id menuUpId, menu_name menuName, menu_url menuUrl, level
FROM sys_menu
where menu_id in (select distinct menu_id
from sys_operator a,
sys_operator_role b,
sys_role c,
sys_role_popedom d
where a.operator_id = b.operator_id
and b.role_id = c.role_id
and d.role_id = d.role_id
and a.operator_id = #userId#)
CONNECT BY menu_up_id = prior menu_id
START WITH menu_up_id = 0
]]>
</select>
<select id="listLog" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
<![CDATA[
select * From oper_log
where oper_happentime = #dateTime#
and operlog_id = #operatorId#
]]>
</select>
<typeAlias alias="User" type="com.newland.gxbc.model.User"/>
<resultMap id="UserResult" class="User">
<result property="userId" column="Oper_Code"/>
<result property="pwd" column="Oper_Pwd"/>
<result property="userName" column="Oper_Name"/>
<result property="userStatus" column="Oper_Status"/>
</resultMap>
<select id="getUserbyUsername" parameterClass="String" resultMap="UserResult">
select * from SYS_OPERATOR WHERE OPER_CODE = #userId#
</select>
</sqlMap>
在sqlMap-config.xml已经配置:
<sqlMap resource="com/newland/gxbc/dao/ibatis/maps/login.xml"/>,但实际调用的时候说找不到,错误如下:
com.ibatis.sqlmap.client.SqlMapException: There is no statement named getUserbyUsername in this SqlMap.
请知道的高手给指点下是不是配置文件写的有问题。谢谢了
------解决方案--------------------
对是login.getUserbyUsername
看错啦
或者你把sqlMap-config.xml里的<settings >属性配useStatementNamespaces="flase"
------解决方案--------------------
这里:
<typeAlias alias="MenuItem" type="com.newland.gxbc.dto.MenuItem" />
<!-- 菜单树 -->
<select id="listMenuTree" parameterClass="String" resultClass="MenuItem">
最好声明一个resultMap,与你查询的结果对应,就像你声明
<resultMap id="UserResult" class="User">
<result property="User.userId" column="Oper_Code"/>
<result property="User.pwd" column="Oper_Pwd"/>
<result property="User.userName" column="Oper_Name"/>
<result property="User.userStatus" column="Oper_Status"/>
</resultMap> 这个一样。