Java 将多个SessionAttributes导入modelmap
我对Spring还很陌生,所以如果这个问题看起来很简单或明显,我很抱歉,但我试图寻找这个问题的答案,但这辆巴士找不到它。所以我的问题是如何使用多个SessionAttributes,并用一种方法将它们放到地图中 i、 e.我有一个@Controller,它使用SessionAttributes:Java 将多个SessionAttributes导入modelmap,java,spring,web,controller,mapping,Java,Spring,Web,Controller,Mapping,我对Spring还很陌生,所以如果这个问题看起来很简单或明显,我很抱歉,但我试图寻找这个问题的答案,但这辆巴士找不到它。所以我的问题是如何使用多个SessionAttributes,并用一种方法将它们放到地图中 i、 e.我有一个@Controller,它使用SessionAttributes: @Controller @SessionAttributes({"name", "lastName", "birthDate"}) public class SearchController {
@Controller
@SessionAttributes({"name", "lastName", "birthDate"})
public class SearchController {
@RequestMapping(value = "/your-relatives")
public String findRelatives(ModelMap model) {
String name = (String) model.get("name");
String lastName = (String) model.get("lastName");
String birthDate = (String) model.get("birthDate");
if (name.equals("John") && lastName.equals("Johnny")) {
return "YES";
}
return "NO";
}
}
但是当我试图在if为true的情况下返回“YES”时,我得到了错误——出现了意外错误(type=internalserver error,status=500)。
没有可用的消息
它仅在使用其中一个属性时有效。您的sessoinAttributes
name
和lastName
中到底有什么内容?顺便问一下什么是是?html?name和lastName是从用户登录中获取的字符串值。现在是返回文本的简单hmtl文件。确保作为用户输入的字符串与John
和johny
的大写字母J完全匹配。如果大小写与您无关,您可以使用name.equalsIgnoreCase(“John”)和&lastName.equalsIgnoreCase(“Johnny”)
但如果大小写不匹配,是否应返回“否”,并插入“是”?因为现在我得到的是错误500,根本没有返回值。从技术上讲,no
应该是一个错误页面。