本文主要是介绍[已解决]HTTP Status 404 - No result defined for action xxx and result exception问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在做crm项目练习时,发现在添加客户的时候页面出现HTTP Status 404 - No result defined for action xxx and result exception错误,而控制台没有报任何错误信息。
Action类
package com.tangseng.web.action;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tangseng.domain.Customer;
import com.tangseng.service.CustomerService;
import com.tangseng.utils.PageBean;public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {//接收表单传入参数private Customer customer = new Customer();private Integer currentPage;private Integer pageSize;//获得serviceprivate CustomerService cs;//查询分页列表public String list(){//调用service层处理分页逻辑,返回pageBeanPageBean pb = cs.getPageBean(customer,currentPage,pageSize);pb.setSearchname(customer.getCust_name());//将pageBean封装到request域中ActionContext.getContext().put("pageBean", pb);return "list";}public String add(){cs.save(customer);return "tolist";}@Overridepublic Customer getModel() {return customer;}public void setCurrentPage(Integer currentPage) {this.currentPage = currentPage;}public void setPageSize(Integer pageSize) {this.pageSize = pageSize;}public void setCs(CustomerService cs) {this.cs = cs;}public Customer getCustomer() {return customer;}public void setCustomer(Customer customer) {this.customer = customer;}public Integer getCurrentPage() {return currentPage;}public Integer getPageSize() {return pageSize;}}
service类
package com.tangseng.service.Imp;import java.util.List;import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;import org.apache.commons.lang3.StringUtils;
import com.tangseng.dao.CustomerDao;
import com.tangseng.domain.Customer;
import com.tangseng.service.CustomerService;
import com.tangseng.utils.PageBean;public class CustomerServiceImp implements CustomerService {private CustomerDao cd;public void setCd(CustomerDao cd) {this.cd = cd;}@Overridepublic PageBean getPageBean(Customer customer, Integer currentPage, Integer pageSize) {//封装离线查询对象DetachedCriteria dc = DetachedCriteria.forClass(Customer.class);if(StringUtils.isNotBlank(customer.getCust_name())){dc.add(Restrictions.like("cust_name", "%"+customer.getCust_name()+"%"));}//根据条件查询总记录数Integer totalCount = cd.findTotalCount(dc);//封装pageBean对象PageBean pb = new PageBean(currentPage, totalCount, pageSize);//计算索引(在pageBean中算好)//根据条件查询列表List<Customer> customerlist = cd.findPageList(dc,pb);//整合pageBean返回pb.setList(customerlist);return pb;}@Overridepublic void save(Customer customer) {System.out.println(customer.toString());cd.saveorupdate(customer);}}
BaseDao类
package com.tangseng.dao.Imp;import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;import com.tangseng.dao.BaseDao;
import com.tangseng.utils.PageBean;public class BaseDaoImp<T> extends HibernateDaoSupport implements BaseDao<T> {private Class clazz;//用于接收运行时的泛型类型public BaseDaoImp(){//获得当前类型的带有泛型的父类ParameterizedType genericSuperclass = (ParameterizedType) this.getClass().getGenericSuperclass();//获得运行期的泛型类型clazz = (Class) genericSuperclass.getActualTypeArguments()[0];}@Overridepublic void save(T t) {getHibernateTemplate().save(t);}@Overridepublic void delete(T t) {getHibernateTemplate().delete(t);}@Overridepublic void delete(Serializable id) {T t = findById(id);delete(t);}@Overridepublic void modify(T t) {getHibernateTemplate().update(t);}@Overridepublic T findById(Serializable id) {T t = (T) getHibernateTemplate().get(clazz, id);return t;}@Overridepublic Integer findTotalCount(DetachedCriteria dc) {Integer totalcount = null;dc.setProjection(Projections.rowCount());List totalcountlist = getHibernateTemplate().findByCriteria(dc);if(totalcountlist.size()>0&&totalcountlist!=null){String string = totalcountlist.get(0).toString();totalcount = Integer.parseInt(string);}//清空函数查询dc.setProjection(null);return totalcount;}@Overridepublic List<T> findPageList(DetachedCriteria dc, PageBean pb) {//分页查询操作List<T> list = (List<T>) getHibernateTemplate().findByCriteria(dc, pb.getBegin(), pb.getPageSize());return list;}@Overridepublic List<T> findList(DetachedCriteria dc) {return (List<T>) getHibernateTemplate().findByCriteria(dc);}@Overridepublic void saveorupdate(T t) {getHibernateTemplate().saveOrUpdate(t);}}
Dao实现类
package com.tangseng.dao.Imp;
import com.tangseng.dao.CustomerDao;
import com.tangseng.domain.Customer;public class CustomerDaoImp extends BaseDaoImp<Customer> implements CustomerDao {}
通过测试add方法接收参数正常,在debug模式下,当断点执行到getHibernateTemplate().saveorUpdate方法时跳转到ognl源码(看不懂),最后再页面输出错误信息,而控制台没有出现错误信息
点击保存,控制台打印接收到的参数
基本确定是getHibernateTemplate().saveorUpdate这个代码产生的问题,刚刚才发现,原来是事务没有提交。
原因在与配置Spring切入点的时候把,切入点配到Dao层去了。
要把Spring切入点配到service层的方法上才行
这篇关于[已解决]HTTP Status 404 - No result defined for action xxx and result exception问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!