出错代码如下:
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)
我的代码如下:
UserDaoIbatis.java的代码如下
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);
}
}
User.java的代码如下
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;
}
}
我的几个配置文件
applicationContext-ibatis.xml的配置如下
<?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>
sql-map-config.xml的配置如下
<?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>
User.xml的配置如下
<?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>
分享到:
相关推荐
sping + ibatissping + ibatissping + ibatissping + ibatissping + ibatissping + ibatissping + ibatissping + ibatis
在这个“struts2+spring3+ibatis项目整合案例”中,我们将深入探讨这三个框架如何相互配合,实现项目的集成。 Struts2作为MVC(Model-View-Controller)架构的实现,主要负责处理用户请求,控制应用的流程。它提供...
标题 "spring+ibatis" 暗示了我们即将探讨的是如何在Java应用程序中整合Spring框架与iBatis SQL映射框架。iBatis是一个轻量级的数据访问层框架,它允许开发者将SQL语句直接写在配置文件中,而Spring则是一个全面的...
通过XML或注解定义SQL映射文件,iBATIS能够自动执行SQL并处理结果集,极大地提高了开发效率。 二、Spring与iBATIS整合 1. 配置SqlMapClient 首先,我们需要在项目中引入iBATIS的相关库,并在Spring配置文件中定义...
Struts1.2+Struts2.1.6+spring 2.0+hibernate3.1+Ibatis2.3 SSH
SSH(Struts + Spring + Hibernate)集成模板为开发者提供了一个快速开发的基础,使得开发者能够更快地搭建项目,专注于业务逻辑的实现。 首先,Struts是MVC(Model-View-Controller)架构模式的一种实现,主要用于...
struts+sping+hibernate
Spring作为一个轻量级的框架,有很多的拓展功能,最主要的我们一般项目使用的就是IOC和AOP。 SpringMVC是Spring实现的一个Web层,相当于Struts的框架,但是比Struts更加灵活和强大! Mybatis是 一个持久层的框架,在...
struts+sping+hibernate
struts+sping+hibernate
struts+sping+hibernate
在"轻量级Java ee企业应用实战struts2+sping+hibernate整合开发源码(3.9)"这个项目中,开发者可能已经完成了以下关键模块的搭建: 1. **配置文件**:包括struts2的struts.xml,Spring的applicationContext.xml,...
遗憾的是,它没有涉及Dubbo与Spring Boot、Redis、Zookeeper、Seata和RabbitMQ的集成,但作为基础,这个例子对于理解服务治理和服务发现的核心概念至关重要。 【知识点】 1. **Dubbo**:Dubbo是阿里巴巴开源的一个...
struts+sping+hibernate qq群72861940
Struts+sping+Hibernate
struts+sping+hibernate qq群72861940
struts+sping+hibernate qq群72861940
struts+sping+hibernate qq群72861940
struts+sping+hibernate qq群72861940
struts+sping+hibernate qq群72861940