action可否直接使用spring的声明式事务?
由于图省事,而且系统比较小,感觉service层比较繁琐,就直接在action里调用的dao
现在想使用事务 action代码大致如下
public ActionForward addOrg(orginfoDAO.insert(orginfo);userDAO.insert(userInfo);}
<bean id="transactionManager" lazy-init="true" name="code"> <bean name="/userOrgManager" name="code">public class ActionAdatper extends Action {protected ActionDispatcher dispatcher ;protected Action action;@Overridepublic void setServlet(ActionServlet servlet) {super.setServlet(servlet);this.action.setServlet(servlet);}public ActionAdatper(Action action){action.setServlet(servlet);dispatcher = new ActionDispatcher(action,ActionDispatcher.DISPATCH_FLAVOR);}public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {return dispatcher.execute(mapping, form, request, response);}}
public class NewerDelegatingRequestProcessor extends DelegatingRequestProcessor {protected Action getDelegateAction(ActionMapping mapping) throws BeansException {Action action=super.getDelegateAction(mapping);if(action==null){return null;}return new ActionAdatper(action);}}
@Transactional(readOnly=false)public class XXXXAction extends Action {/** * * 新增页面初始化处理 * */public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {}/** * 修改页面初始化处理 * */public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { }}public class ActionAdatper extends Action {protected ActionDispatcher dispatcher ;protected Action action;@Overridepublic void setServlet(ActionServlet servlet) {super.setServlet(servlet);this.action.setServlet(servlet);}public ActionAdatper(Action action){action.setServlet(servlet);dispatcher = new ActionDispatcher(action,ActionDispatcher.DISPATCH_FLAVOR);}public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {return dispatcher.execute(mapping, form, request, response);}}
public class NewerDelegatingRequestProcessor extends DelegatingRequestProcessor {protected Action getDelegateAction(ActionMapping mapping) throws BeansException {Action action=super.getDelegateAction(mapping);if(action==null){return null;}return new ActionAdatper(action);}}
@Transactional(readOnly=false)public class XXXXAction extends Action {/** * * 新增页面初始化处理 * */public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {}/** * 修改页面初始化处理 * */public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { }}