我在Spring中设置了一个RestController,我有一个模糊的映射问题。我没有看到最后两个方法是如何模糊的,因为请求映射和方法名称是不同的。当我从上一个方法中删除方法规范时,问题就不存在了。
@Controller
@RequestMapping({ “/注释/ AIT /”}) 公共类AitController扩展了BaseController {
@Autowired
private AitService aitService;
@ResponseBody
@RequestMapping(value = {"addAit"}, method = {RequestMethod.POST})
public int addAit(CommentAitVo aitVo, @RequestParam(name = "commentType") CommentType commentType) {
aitVo.setCommentType(commentType.value);
aitVo.setCreateuserid(getUserId());
aitVo.setCreatetime(new Date());
return aitService.addCommentAit(aitVo);
}
@ResponseBody
@RequestMapping(value = {"readedAit"}, method = {RequestMethod.POST})
public int readedAit(@RequestParam(name = "id") Long id) {
return aitService.readedCommentAit(id);
}
@ResponseBody
@RequestMapping(value = {"delAit"}, method = {RequestMethod.POST})
public int delAit(@RequestParam(name = "id") Long id) {
return aitService.delCommentAit(id);
}
@RequestMapping(value = {"getAitList"}, method = {RequestMethod.GET})
@ResponseBody
public List<CommentAitVo> getAitList(@RequestParam(name = "receiverId") String receiverId, PageQuery query) {
return aitService.getCommentAitRecordList(query, receiverId).getList();
}
}
会导致此错误:
RequestID: 2018-05-24 17:51:30.753 WARN [main] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext [?] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'aitController' method
public java.util.List<com.meicloud.saas.comment.vo.CommentAitVo> com.meicloud.saas.comment.console.controller.AitController.getAitList(java.lang.String,com.meicloud.paas.core.beans.PageQuery)
to {[/saas-api/comment/ait/getAitList],methods=[GET]}: There is already 'com.meicloud.saas.comment.console.controller.AitController#0' bean method