小编tju*_*icz的帖子

为什么我必须在实现类而不是接口类上使用`@RequestParam`注释?

为什么我必须@RequestParam在实现类而不是接口类上使用注释?我在单独的文件方法中使用接口和实现.似乎@RequestParamon接口的使用没有效果.

public interface GreetingService {

    @RequestMapping(value = "/greeting", method = RequestMethod.GET)
    public Greeting greetingByGet(@RequestParam(value="name", defaultValue="World") String name);

}

@RestController
public class GreetingController implements GreetingService {

    @Override
    public Greeting greetingByGet(
    /** 
    * Why do I need to duplicate @RequestParam annotation on 
    * implementation to make it work ??? 
    * Otherwise GET default value is not used. 
    */ 
    @RequestParam(value="name", defaultValue="World")
    String name) {

        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

它是有意义的注解像@Transactional这是实现特定的,但@RequestParam,@RequestBody等实现特定的?或者这是接口合同的一部分?@RequestBody(required)建议它是合同的一部分,因此应该支持在接口上使用它.

这里有一个解释:Spring MVC …

java spring spring-mvc

2
推荐指数
1
解决办法
1141
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1