ibatis中sqlmap调用问题
我在sqlmap中定义了增删查改的sql语句,在类中,查询可以调用,增加和修改不行,报错如下: com.ibatis.sqlmap.client.SqlMapException: There is no statement named users.insert in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:367)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
at com.qy.system.UsersManager.addUser(UsersManager.java:63)
at com.qy.system.UsersManager.main(UsersManager.java:149)
SQLMap代码如下:
<sqlMap namespace="USERS">
<typeAlias alias="users" type="com.qy.model.Users" />
<typeAlias alias="hashmap" type="java.util.Map" />
<parameterMap class="users" id="users.param">
<parameter property="userUsername" javaType="String" />
<parameter property="userPassword" javaType="String" />
</parameterMap>
<select id="users.count" resultClass="int" parameterMap="users.param">
select
count(*) from users where user_username=? and
user_password=?
</select>
<resultMap class="users" id="user.map">
<result property="userId" column="user_id" />
<result property="userUsername" column="user_username" />
<result property="userPassword" column="user_password" />
<result property="userSex" column="user_Sex" />
</resultMap>
<select id="users.selectAll" resultMap="user.map">
select * from users
</select>
<insert id="users.insert" parameterClass="hashmap">
insert into users(
user_id,
user_username,
user_password,
user_sex
)
values(
#id:Integer#,
#name:varchar#,
#pwd:varchar#,
#sex:Integer#)
</insert>
<update id="users.update" parameterClass="hashmap">
update users set user_username=#name#,user_password=#pwd#,user_sex=#sex# where user_id=#id#
</update>
</sqlMap>
------解决方案--------------------
你的id不要用users.*,直接用count这种就可以了。users是你的命名空间。