【发布时间】:2018-09-22 09:21:07
【问题描述】:
我的 Spring Boot 项目中有以下控制器类,分为接口和实现:
public interface UserAccountController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestBody UserAccountEntity account,
HttpServletResponse response) throws IOException;
@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String create(@Valid @RequestBody UserAccountEntity userAccount,
HttpServletResponse response, BindingResult result);
}
@RestController
@RequestMapping("/api/authentication")
public class UserAccountControllerImpl implements UserAccountController {
@Autowired
private UserAccountService userAccountService;
@Override
public String login(@Valid @RequestBody UserAccountEntity account,
HttpServletResponse response) throws IOException {
//...
}
@Override
public String create(@Valid @RequestBody UserAccountEntity userAccount,
HttpServletResponse response, BindingResult result) {
//....
}
}
当我将 RestController 和 RequestMapping 注释移动到接口时,它不起作用。但是在接口上注释方法是有效的。这两个注释有何不同?
【问题讨论】:
标签: java spring-boot