[已解决]HTTP Status 404 - No result defined for action xxx and result exception问题

2024-08-29 15:58

本文主要是介绍[已解决]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问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1118305

相关文章

Springboot3统一返回类设计全过程(从问题到实现)

《Springboot3统一返回类设计全过程(从问题到实现)》文章介绍了如何在SpringBoot3中设计一个统一返回类,以实现前后端接口返回格式的一致性,该类包含状态码、描述信息、业务数据和时间戳,... 目录Spring Boot 3 统一返回类设计:从问题到实现一、核心需求:统一返回类要解决什么问题?

解决idea启动项目报错java: OutOfMemoryError: insufficient memory

《解决idea启动项目报错java:OutOfMemoryError:insufficientmemory》:本文主要介绍解决idea启动项目报错java:OutOfMemoryError... 目录原因:解决:总结 原因:在Java中遇到OutOfMemoryError: insufficient me

maven异常Invalid bound statement(not found)的问题解决

《maven异常Invalidboundstatement(notfound)的问题解决》本文详细介绍了Maven项目中常见的Invalidboundstatement异常及其解决方案,文中通过... 目录Maven异常:Invalid bound statement (not found) 详解问题描述可

idea粘贴空格时显示NBSP的问题及解决方案

《idea粘贴空格时显示NBSP的问题及解决方案》在IDEA中粘贴代码时出现大量空格占位符NBSP,可以通过取消勾选AdvancedSettings中的相应选项来解决... 目录1、背景介绍2、解决办法3、处理完成总结1、背景介绍python在idehttp://www.chinasem.cna粘贴代码,出

SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)

《SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)》本文总结了SpringBoot项目整合Kafka启动失败的常见错误,包括Kafka服务器连接问题、序列化配置错误、依赖配置问题、... 目录一、Kafka服务器连接问题1. Kafka服务器无法连接2. 开发环境与生产环境网络不通二、序

SpringSecurity中的跨域问题处理方案

《SpringSecurity中的跨域问题处理方案》本文介绍了跨域资源共享(CORS)技术在JavaEE开发中的应用,详细讲解了CORS的工作原理,包括简单请求和非简单请求的处理方式,本文结合实例代码... 目录1.什么是CORS2.简单请求3.非简单请求4.Spring跨域解决方案4.1.@CrossOr

nacos服务无法注册到nacos服务中心问题及解决

《nacos服务无法注册到nacos服务中心问题及解决》本文详细描述了在Linux服务器上使用Tomcat启动Java程序时,服务无法注册到Nacos的排查过程,通过一系列排查步骤,发现问题出在Tom... 目录简介依赖异常情况排查断点调试原因解决NacosRegisterOnWar结果总结简介1、程序在

Java Exception异常类的继承体系详解

《JavaException异常类的继承体系详解》Java中的异常处理机制分为异常(Exception)和错误(Error)两大类,异常分为编译时异常(CheckedException)和运行时异常... 目录1. 异常类的继承体系2. Error错误3. Exception异常3.1 编译时异常: Che

Java Exception与RuntimeException使用及说明

《JavaException与RuntimeException使用及说明》:本文主要介绍JavaException与RuntimeException使用及说明,具有很好的参考价值,希望对大家有所... 目录简介ExceptionRuntimeException自定义异常选择继承Exception(受检异常)

解决java.util.RandomAccessSubList cannot be cast to java.util.ArrayList错误的问题

《解决java.util.RandomAccessSubListcannotbecasttojava.util.ArrayList错误的问题》当你尝试将RandomAccessSubList... 目录Java.util.RandomAccessSubList cannot be cast to java.