struts2+hibernate+spring项目action中无法更新和添加数据
更新数据库的action
destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/jxcgl?useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>19880222</value>
</property>
<property name="minPoolSize">
<value>3</value>
</property>
<property name="maxPoolSize">
<value>20</value>
</property>
<property name="initialPoolSize">
<value>10</value>
</property>
<property name="maxIdleTime">
<value>60</value>
</property>
<property name="acquireIncrement">
<value>5</value>
</property>
<property name="maxStatements">
<value>0</value>
</property>
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<property name="breakAfterAcquireFailure">
<value>true</value>
</property>
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/entity/User.hbm.xml</value>
<value>com/entity/Dept.hbm.xml</value>
<value>com/entity/Chanpinxinxi.hbm.xml</value>
<value>com/entity/Kehuxinxi.hbm.xml</value>
<value>com/entity/Type.hbm.xml</value>
<value>com/entity/Producttype.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- Create/update the database tables automatically when the JVM starts up
<prop key="hibernate.hbm2ddl.auto">update</prop> -->
<!-- Turn batching off for better error messages under PostgreSQL
<prop key="hibernate.jdbc.batch_size">100</prop> -->
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="connection.autocommit">true</prop>
</props>
</property>
</bean>
<!-- 以下为事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用基于注释式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="userDaoImpl" class="com.dao.impl.UserDaoImpl"></bean>
<bean id="chanpinxinxiDaoImpl" class="com.dao.impl.ChanpinxinxiDaoImpl"></bean>
<bean id="producttypeDaoImpl" class="com.dao.impl.ProducttypeDaoImpl"></bean>
<bean id="kehuxinxiDaoImpl" class="com.dao.impl.KehuxinxiDaoImpl"></bean>
<bean id="typeDaoImpl" class="com.dao.impl.TypeDaoImpl"></bean>
</beans>
<!-- 添加产品信息addProduct.jsp中的内容 -->
<action name="addchanpinxinxi" class="addchanpinxinxiAction">
<result name="success" type="json">
</result>
</action>
package com.action;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import com.dao.ChanpinxinxiDao;
import com.dao.KehuxinxiDao;
import com.dao.ProducttypeDao;
import com.dao.TypeDao;
import com.entity.Chanpinxinxi;
import com.entity.Kehuxinxi;
import com.entity.Producttype;
import com.entity.Type;
/**
* 增加产品信息中的内容
* @author think
*
*/
@Controller
public class AddchanpinxinxiAction extends XinGaoAction{
@Resource ProducttypeDao protypedao;
@Resource ChanpinxinxiDao cpxxdao;
@Resource KehuxinxiDao khxxdao;
@Resource TypeDao typedao;
private String pname;//名称
private int types;//类型
private String pspecs;//规格
private double price;//价格
private int pstate;//状态
private int kehus;//厂商
private boolean ok=false;
public String execute(){
Producttype protype=new Producttype();
Type type=new Type();
Kehuxinxi khxx=new Kehuxinxi();
Chanpinxinxi cpxx=new Chanpinxinxi();
try {
protype=protypedao.findById(types);
type=typedao.findById(pstate);
khxx=khxxdao.findById(kehus);
cpxx.setChanpinmingcheng(pname);
cpxx.setChanpinmobanbianhao(0);//产品编号
cpxx.setDingdanbianhao(0);//订单编号
cpxx.setGuige(pspecs);
cpxx.setJiage(price);
cpxx.setJine("");
cpxx.setKehuxinxi(khxx);
cpxx.setProducttype(protype);
cpxx.setType(type);
//保存产品信息
cpxxdao.savaCPXX(cpxx);
ok=true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
ok=false;
}
return "success";
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public int getTypes() {
return types;
}
public void setTypes(int types) {
this.types = types;
}
public String getPspecs() {
return pspecs;
}
public void setPspecs(String pspecs) {
this.pspecs = pspecs;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getPstate() {
return pstate;
}
public void setPstate(int pstate) {
this.pstate = pstate;
}
public int getKehus() {
return kehus;
}
public void setKehus(int kehus) {
this.kehus = kehus;
}
public boolean isOk() {
return ok;
}
public void setOk(boolean ok) {
this.ok = ok;
}
}
数据库建表语句不要忘了。