springmvc jpa mysql_SpringMvc Jpa mysql开发项目,事务失效,现象:Controller增加和修

收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 SpringMvc Jpa mysql开发项目,事务失效,现象:Controller增加和修改无效,但单元测试可以,不知道什么原因,代码如下:

各位高手帮忙解决一下啊,谢谢了。

实体类:

@Entity

public class Customer implements Serializable{

private static final long serialVersionUID = -803075682525328610L;

private Integer customerId;

private String loginName;

private String password="123456";

private String nickName;

private String email;

private String cellphone;

@Id @GeneratedValue

public Integer getCustomerId() {

return customerId;

}

}

DAO:

public interface DAO {

public void save(Object entity);

}

DAO抽象类:

@Transactional

public abstract class DaoSupport implements DAO {

protected Class entityClass = GenericsUtils.getSuperClassGenricType(this.getClass());

@PersistenceContext protected EntityManager em;

public void save(Object entity) {

em.persist(entity);

}

}

Service层:

public interface CustomerService extends DAO{

}

@Service

@Transactional

public class CustomerServiceBean extends DaoSupport implements CustomerService {

}

Controller层:

@Controller

public class ModiPersonDataController {

@Resource CustomerService customerService;

@RequestMapping("/modiPersonDataUI.do")

public String jumpToModiUI() {

return "modiPersonData";

}

/**

* 修改个人资料和密码

*/

@RequestMapping("/modiPersonData.do")

public void modiPersonData(CustomerForm customerForm){

Customer customer = new Customer();

customer.setLoginName(customerForm.getLoginName());

customer.setPassword(customerForm.getPassword());

customer.setNickName(customerForm.getNickName());

customer.setCellphone(customerForm.getCellphone());

customer.setEmail(customerForm.getEmail());

customerService.save(customer);

}

}

webform层:

public class CustomerForm implements Serializable{

private static final long serialVersionUID = -4425312158083346598L;

private Integer customerId;

private String loginName;

private String password;

private String nickName;

private String cellphone;

private String email;

public String getLoginName() {

return loginName;

}

。。。

}

persistence.xml 配置如下:

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

org.hibernate.ejb.HibernatePersistence

beans.xml配置如下:

jdbc.properties)(略)

spring mvc 配置如下:

p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>

web.xml 配置如下:

Spring Annotation MVC Sample

contextConfigLocation

classpath:beans.xml

org.springframework.web.context.ContextLoaderListener

annomvc

org.springframework.web.servlet.DispatcherServlet

2

annomvc

*.do

[该贴被zhaome于2010-03-16 16:36修改过]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值