gpt4 book ai didi

spring-mvc - 模型和 View 向前

转载 作者:行者123 更新时间:2023-12-05 01:18:40 24 4
gpt4 key购买 nike

Spring MVC ModelAndView forward 不工作。下面的代码没有将请求转发到 Name.jsp。非常感谢您的帮助。

package main.java.com.mkyong.common.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class indexController {@RequestMapping(value= {"/index"})
public ModelAndView forward() {
ModelAndView model = new ModelAndView( "forward:/pages/Name.jsp");
model.addObject("msg","Forward Handled");
return model;

}}

最佳答案

您需要将返回类型替换为 String 并返回 "forward:/some/where/",因此,您的请求处理程序将如下所示:

package main.java.com.mkyong.common.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class indexController {@RequestMapping(value= {"/index"})
public String forward() {
model.addObject("msg","Forward Handled");
return "forward:/some/where/to/go";

}}

关于spring-mvc - 模型和 View 向前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27633933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com