SSH2只能添加不能修改删除,求解
据说跟事务有关 看了下事务配置,求大虾帮忙看看。
<!--
对事务管理器进行事务设置。增加如下代码: 这里创建了一个advice(通知),对事务管理器进行事务设置,这里意思是指,
对于以save、del、update开头的方法应用事务。
-->
<tx:advice id="smAdvice" transaction-manager="transactionManager">
<!-- 设置事务传播属性 -->
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" />
<tx:method name="display*" propagation="REQUIRED" />
<tx:method name="view*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 下面就把事务应用到具体的类 -->
<aop:config>
<!--
<aop:pointcut id="smMethod" expression="execution(*
cn.app.cost.buz.impl.*.*(..))"/>
-->
<aop:pointcut id="smMethod" expression="execution(* cn.*.buz.impl.*.*(..))" />
<aop:advisor pointcut-ref="smMethod" advice-ref="smAdvice" />
</aop:config>
package cn.action;ssh2 事务 aop
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.hibernate.NonUniqueResultException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.model.Roomusage;
import cn.page.PageBean;
import cn.service.RoomusageService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.opensymphony.xwork2.ActionContext;
@Controller
public class RoomusageManagerAction extends JqGridBaseAction<Roomusage> {
@Resource
RoomusageService roomusageService;
private Integer r_u_id;
private Roomusage roomusage;
private Integer pageNo = 1;
private PageBean pageBean;
private Integer rowPerPage;
private Integer totalCount;
private String result;
private String ajaxResult;
public String getAjaxResult() {
return ajaxResult;
}
public void setAjaxResult(String ajaxResult) {
this.ajaxResult = ajaxResult;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
public Integer getRowPerPage() {
return rowPerPage;
}
public void setRowPerPage(Integer rowPerPage) {
this.rowPerPage = rowPerPage;
}
public PageBean getPageBean() {
return pageBean;
}
public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}
public Integer getPageNo() {
return pageNo;
}
public void setPageNo(Integer pageNo) {
this.pageNo = pageNo;
}
public Integer getR_u_id() {
return r_u_id;
}
public void setR_u_id(Integer r_u_id) {
this.r_u_id = r_u_id;
}
public Roomusage getRoomusage() {
return roomusage;
}
public void setRoomusage(Roomusage roomusage) {
this.roomusage = roomusage;
}
public String execute() {
return this.refreshGridModel();
}
public String viewRoomusage() {
int id = roomusage.getR_u_id();
roomusage = roomusageService.get(roomusage.getR_u_id());
if (roomusage == null) {
ajaxResult = "未能找到ID为 " + id + " 的联系人";
return ERROR;
}
ajaxResult = SUCCESS;
return SUCCESS;
}
public String createRoomusage() {
try {
System.out.print(roomusage.getR_u_name()+roomusage.getR_u_id());
this.roomusageService.save(roomusage);
ajaxResult = SUCCESS;
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
this.addActionError(e.getMessage());
ajaxResult = "创建房间用途失败!" + e.getMessage();
return ERROR;
}
}
// 更新Contact信息
public String updateRoomusage() {
try {
this.roomusageService.update(roomusage);
} catch (Exception e) {
e.printStackTrace();
this.addActionError(e.getMessage());
ajaxResult = "更新房间用途失败!" + e.getMessage();
return ERROR;
}
ajaxResult = SUCCESS;
return SUCCESS;
}
// 删除Contact
public String deleteRoomusage() {
try {
this.roomusageService.delete(roomusage.getR_u_id());
} catch (Exception e) {
e.printStackTrace();
this.addActionError(e.getMessage());
ajaxResult = "删除房间用途失败!" + e.getMessage();
return ERROR;
}
ajaxResult = SUCCESS;
return SUCCESS;
}
public String addUI() {
return "add";
}
public String updateUI() {
if (roomusage == null) {
roomusage = new Roomusage();
}
roomusage = roomusageService.get(r_u_id);
return "add";
}
public String del() {
if (roomusageService.get(r_u_id) != null) {
roomusageService.delete(r_u_id);
ActionContext.getContext().put("message", "删除成功");
} else {
ActionContext.getContext().put("message", "没有该宿舍区域");
}
return "message";
}
@SuppressWarnings("finally")
public String saveorupdate() {
try {
if (roomusageService.get(roomusage.getR_u_id()) == null) {
roomusageService.update(roomusage);
ActionContext.getContext().put("message", "保存成功" + roomusage);
} else {
ActionContext.getContext().put("message",
"有重复的宿舍区域" + roomusage);
}
} catch (NonUniqueResultException e) {
ActionContext.getContext().put("message", "重复的宿舍区域不只有一个了!");
} finally {
return "message";
}
}
@Override
public int getResultSize() {
// TODO Auto-generated method stub
return roomusageService.list().size();
}
@Override
public List<Roomusage> listResults(int from, int length) {
List<Roomusage> results = Collections.emptyList();
results = roomusageService.roomusagePage(from, length).getData();
return results;
}
public void addActionError(String anErrorMessage){
String s=anErrorMessage;
System.out.println(s);
}
public void addActionMessage(String aMessage){
String s=aMessage;
System.out.println(s);
}
public void addFieldError(String fieldName, String errorMessage){
String s=errorMessage;
String f=fieldName;
System.out.println(s);
System.out.println(f);
}
}