小编Yev*_*Yev的帖子

spring mvc 控制器 - 缺少名为“xyz”的 cookie

我有一个现有的控制器方法

@RequestMapping(value = "/{productId}", method = RequestMethod.GET)
public ModelAndView getProduct(@PathVariable String productId){
 // code in this method does not matter
}
Run Code Online (Sandbox Code Playgroud)

我需要通过分析用户的 cookie 来增强这条路线的现有行为。如果用户有名为xyz的 cookie,我需要制作不同的东西。因此,我通过添加第二个参数@CookieValue("xyz") final String xyz创建了getProduct方法 的重载版本:

@RequestMapping(value = "/{productId}", method = RequestMethod.GET)
public ModelAndView getProduct(@PathVariable String productId, @CookieValue("xyz") final String xyz){
 // make some different logic 
}
Run Code Online (Sandbox Code Playgroud)

当我尝试访问此路由时,spring 总是抛出异常

org.springframework.web.bind.ServletRequestBindingException: Missing cookie named 'xyz' for method parameter type [java.lang.String]
Run Code Online (Sandbox Code Playgroud)

显然,方法 getProduct 的重载版本总是被调用。

我该如何修复这个错误?是否有任何注释表明 cookie 值是可选的?

mapping cookies spring-mvc optional-parameters spring-3

5
推荐指数
1
解决办法
2641
查看次数

Struts 2 if tag : 用常量测试

我正在制作以下代码:

<s:if test="%{#beanVar == com.mycompany.project.NOT_REGISTERED} ">
 <td>NOT REGISTRED</td>
</s:if>
Run Code Online (Sandbox Code Playgroud)

其中com.mycompany.project.NOT_REGISTERED是一个类静态字段:

public static final long NOT_REGISTERED == 0;
Run Code Online (Sandbox Code Playgroud)

我在 Struts2 文档中找不到在运行时评估中公开常量的方法。

在此先感谢您的帮助。

PS:我不想使用老式的构造 <% %>

if-statement struts2 constants

4
推荐指数
1
解决办法
3502
查看次数