sping+ibatis集成开发时出错

出错代码如下:
[code]
com.ibatis.sqlmap.client.SqlMapException: There is no statement named getUser
in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:293)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:557)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:210)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:168)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:208)
at com.tom.test.ibatis.dao.ibatis.UserDaoIbatis.getUser(Unknown Source)
at com.tom.test.ibatis.service.impl.UserServiceImpl.getUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.getUser(Unknown Source)
[/code]
我的代码如下:
UserDaoIbatis.java的代码如下
[code]
public class UserDaoIbatis extends BaseDao implements UserDao {

public User getUser(Integer id){

return (User) this.getSqlMapClientTemplate().queryForObject(
"getUser", id);
}

public Collection getUsers(){

return this.getSqlMapClientTemplate().queryForList("getAllObjects", null);
}

public void saveUser(User user) throws DataAccessException {
this.getSqlMapClientTemplate().insert("insertObject", user);

}

}
[/code]
User.java的代码如下
[code]
public class User extends BaseBean{

/**
*
*/
private static final long serialVersionUID = 1L;

private Integer Id;

private String userName;

private String userInfo;

public Integer getId() {
return Id;
}

public void setId(Integer id) {
Id = id;
}

public String getUserInfo() {
return userInfo;
}

public void setUserInfo(String userInfo) {
this.userInfo = userInfo;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

}
[/code]
我的几个配置文件
applicationContext-ibatis.xml的配置如下
[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/classes/config.properties</value>
</list>
</property>
</bean>
<!--Init datasource-->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>${c3p0.driverClass}</value>
</property>
<property name="jdbcUrl">
<value>${c3p0.jdbcUrl}</value>
</property>
<property name="user">
<value>${c3p0.user}</value>
</property>
<property name="password">
<value>${c3p0.password}</value>
</property>
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${c3p0.maxPoolSize}</value>
</property>
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<property name="maxIdleTime">
<value>${c3p0.maxIdleTime}</value>
</property>
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" ><value>classpath:com/tom/test/ibatis/dao/ibatis/sql-map-config.xml</value></property>
</bean>
<bean id="dao" class="com.tom.test.ibatis.basedao.BaseDao">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="sqlMapClient"><ref local="sqlMapClient"/></property>
</bean>
<bean id="userDao" class="com.tom.test.ibatis.dao.ibatis.UserDaoIbatis">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="sqlMapClient"><ref local="sqlMapClient"/></property>
</bean>

</beans>
[/code]
sql-map-config.xml的配置如下
[code]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings enhancementEnabled="true" maxTransactions="10"
maxRequests="128" maxSessions="20"/>
<sqlMap resource="com/tom/test/ibatis/bean/User.xml"/>
</sqlMapConfig>
[/code]
User.xml的配置如下
[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sql-map namespace="User">
<typeAlias alias="User" type="com.tom.test.ibatis.bean.User"/>
<result-map name="UserResult" class="User">
<property name="Id" column="id"/>
<property name="userName" column="user_name"/>
<property name="userInfo" column="user_info"/>
</result-map>
<insert id="insertObject" parameterClass="User">
insert into user (
id,
user_name,
user_info,
values (
#Id#, #userName#, #userInfo#
)
</insert>
<select id="getAllObjects" resultMap="UserResult">
select * from user
</select>
<select id="getUser" parameterClass="Integer" resultClass="User">
select
id as Id,
user_name as userName,
user_info as userInfo
from user
where id = #value#
</select>
</sql-map>
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值