我有一个模拟我的请求的类,比如
class Venue {
private String city;
private String place;
// Respective getters and setters.
}
Run Code Online (Sandbox Code Playgroud)
我想支持一个RESTful URL来获取有关场地的信息.所以我有这样的控制器方法.
@RequestMapping(value = "/venue/{city}/{place}", method = "GET")
public String getVenueDetails(@PathVariable("city") String city, @PathVariable("place") String place, Model model) {
// code
}
Run Code Online (Sandbox Code Playgroud)
有没有办法,我可以说在春天将我的路径变量绑定到模型对象(在本例中为Venue)而不是获取每个单独的参数?
我有SpringBoot应用程序与该依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我在我的控制器上有一个方法如下:
@RequestMapping(value = "/liamo", method = RequestMethod.POST)
@ResponseBody
public XResponse liamo(XRequest xRequest) {
...
return something;
}
Run Code Online (Sandbox Code Playgroud)
我通过AJAX从我的HTML发送一个JSON对象,其中包含一些XRequest类型对象的字段(它是一个没有任何注释的普通POJO).但是我的JSON没有在我的控制器方法中构造成对象,并且它的字段为空.
我错过了我的控制器的自动反序列化?
我正在研究Spring AOP模块,我对AROUND建议的确切运作方式有些怀疑.
阅读官方文档:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
我可以阅读有关AROUND ADVICE的内容:
围绕建议:围绕连接点的建议,例如方法调用.这是最有力的建议.around通知可以在方法调用之前和之后执行自定义行为.它还负责选择是继续加入点还是通过返回自己的返回值或抛出异常来快速建议的方法执行.
这是周围建议的序列图:

因此,根据我的理解,我可以定义一个建议(我的自定义行为),它将在切入点指定的关节点之前和之后执行.
例如,我可以用这种方式定义AROUND ADVICE:
@Around(“execution(@example.Cacheable * rewards.service..*.*(..))”)
public Object cache(ProceedingJoinPoint point) throws Throwable {
Object value = cacheStore.get(cacheKey(point));
if (value == null) {
value = point.proceed();
cacheStore.put(cacheKey(point), value);
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
在调用服务方法之前和之后执行实现的chaching行为.这样对吗?
我无法完全理解的是它是如何使用ProceedingJoinPoint点参数的.
根据我的理解,它用于选择执行或不执行特定操作但具体如何工作?
另一个疑问是如何正确使用AOP建议如何回答以下问题:
如果我想尝试捕获异常,我必须使用哪些建议?
我认为在这种情况下,答案是使用After throw通知,因为当匹配的方法执行通过抛出异常退出时,通知会执行.
但我不确定它,因为根据我的理解,只有在方法抛出异常时才会执行建议.或者在这种情况下我必须使用**AROUND ADVICE*?
TNX