如果魔法转换器(?)找不到@PathVariable的资源,则抛出异常

时间:2015-04-23 18:32:11

标签: spring-mvc spring-boot spring-data-rest

我刚刚发现我可以将控制器的请求参数转换为资源,而无需触摸仓库或注册自定义转换器。我说实话,我不确定这是如何工作的(默认转换器?弹簧数据休息?),但它非常棒。

我唯一想知道的是,如果找不到@PathVariable的资源,则抛出 NullPointerException或ResourceNotFoundException。有谁知道这是否是可能的?

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<School> getSchool(@PathVariable("schoolId") School school) {

    // do I have to throw this manually?
    if (school == null) {
        throw new ResourceNotFoundException();
    }

使用Spring Boot 1.2.1.RELEASE,spring-data-rest,spring-data-jpa。

0 个答案:

没有答案