package com.ghy.www.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@SessionAttributes("b")
public class TestController6 {
@RequestMapping(value = "test51")
public String test51(Model model) throws Exception {
System.out.println("test51");
model.addAttribute("a", "aa");
model.addAttribute("b", "bb");
return "test52";
}
@RequestMapping(value = "test52")
public String test52(@RequestAttribute("a") String a, @RequestAttribute("b") String b, @SessionAttribute(value = "a") String c, @SessionAttribute("b") String d) throws Exception {
System.out.println("test52");
System.out.println("request a=" + a);
System.out.println("request b=" + b);
System.out.println("session a=" + c);
System.out.println("session b=" + d);
return "test1.jsp";
}
}
top code run effect is only console print :
test51
no forward test52
but bottom code run effect is ok:
package com.ghy.www.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@SessionAttributes("b")
public class TestController6 {
@RequestMapping(value = "test51")
public String test51(Model model) throws Exception {
System.out.println("test51");
model.addAttribute("a", "aa");
model.addAttribute("b", "bb");
return "test52";
}
@RequestMapping(value = "test52")
public String test52(@RequestAttribute("a") String a, @RequestAttribute("b") String b, @SessionAttribute(value = "a", required = false) String c, @SessionAttribute("b") String d) throws Exception {
System.out.println("test52");
System.out.println("request a=" + a);
System.out.println("request b=" + b);
System.out.println("session a=" + c);
System.out.println("session b=" + d);
return "test1.jsp";
}
}
Comment From: bclozel
Sorry, but I don't understand this report. It seems we're missing critical information - what's the expected result, what did you get instead? Could you provide a sample application (something we can git clone or download, and run) showing the issue?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Comment From: startjava
@bclozel
bottom 2 method difference required = false。 no "required = false" can not forward。 has "required = false" can forward。
public String test52(@RequestAttribute("a") String a, @RequestAttribute("b") String b, @SessionAttribute(value = "a") String c, @SessionAttribute("b") String d) throws Exception {
public String test52(@RequestAttribute("a") String a, @RequestAttribute("b") String b, @SessionAttribute(value = "a", required = false) String c, @SessionAttribute("b") String d)
Comment From: startjava
can not forward is bug !!
Comment From: bclozel
This doesn't look like a bug to me. The return value for controller handlers is supposed to point to the view name, not another mapping. Have you seen this part of the reference documentation?
If you have more questions, please use StackOverflow.
Comment From: startjava
in SpringMVC ,controller can forward controller , if only forward view name , why use "required = false" code can good work ??
------------------ 原始邮件 ------------------ 发件人: "Brian @.>; 发送时间: 2021年12月21日(星期二) 下午4:46 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [spring-projects/spring-framework] springmvc version 5.3.13 @SessionAttribute has bug ! (Issue #27767)
这对我来说看起来不像是一个错误。 控制器处理程序的返回值应该指向视图名称,而不是另一个映射。你看过参考文档的这部分吗?
如果您有更多问题,请使用 StackOverflow。
— 直接回复此邮件,在 GitHub 上查看,或取消订阅。 使用 GitHub Mobile for iOS或Android随时随地分类通知。 您收到此消息是因为您创作了该线程。消息 ID:<spring-projects/spring-framework/issues/27767/998582952 @ github 。com>