Java 创建名为';requestMappingHandlerMapping';-弹簧靴

Java 创建名为';requestMappingHandlerMapping';-弹簧靴,java,spring-boot,intellij-idea,Java,Spring Boot,Intellij Idea,我在运行时遇到以下错误 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/sp

我在运行时遇到以下错误

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/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'scrcrdsController' method 
com.mastercard.qualityScore.controllers.ScrcrdsController#getSummary(String)
to {GET /api/v1/scrcrds/{id}}: There is already 'scrcrdsController' bean method
com.mastercard.qualityScore.controllers.ScrcrdsController#get(String) mapped.
我需要创建一个新的api,它获取特定id的所有分数,或者可能是两个id的组合。 我该如何解决这个问题?请帮忙

我的控制人如下:

@RestController
@RequestMapping("/api/v1/scrcrds")
public class ScrcrdsController {
    @Autowired
    private ScrcrdRepository scrcrdRepository;

    //list all scrcrd records
    @GetMapping
    public List<Scrcrd> list() {
        return scrcrdRepository.findAll();
    }

    //get summary  of an employee
    @GetMapping(value = "{id}")
    public List<Scrcrd> getSummary(@PathVariable String id) {
        return  scrcrdRepository.findAllById(Collections.singleton(id));
    }

    //get scrcrd record by id
    @GetMapping(value = "{id}")
    public Scrcrd get(@PathVariable String id) {
        return scrcrdRepository.getOne(id);
    }

    //create a new scrcrd record
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)  //to get  201 response instead of 200
    public Scrcrd create(@RequestBody final Scrcrd scrcrd) {
        return scrcrdRepository.saveAndFlush(scrcrd);
    }

    //delete a scrcrd record
    @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
    public void delete(@PathVariable String id) {
        //Also need to check for children records before deleting
        scrcrdRepository.deleteById(id);
    }

    //update a scrcrd record
    @RequestMapping(value = "{id}", method = RequestMethod.PUT)
    public Scrcrd update (@PathVariable String id, @RequestBody Scrcrd scrcrd) {
        //because this is a PUT, we expect all attributes to be passed in. A PATCH would only need what attribute is being modified
        //TODO: Add validation that all attributes are passed in, otherwise return a 400 bad payload
        Scrcrd existingScrcrd = scrcrdRepository.getOne(id);
        //attributes of emp are copied to existingScrcrd, emp_id, mgr_id, mgr_scr_dt and type_nam is not to be changed
        BeanUtils.copyProperties(scrcrd, existingScrcrd   , "emp__id", "mgr_id", "mgr_scr_dt", "type_nam");
        return scrcrdRepository.saveAndFlush(existingScrcrd);
    }
}
@RestController
@请求映射(“/api/v1/scrcrds”)
公共类SCRRDS控制器{
@自动连线
专用SCRRDRepository SCRRDRepository;
//列出所有SCRRD记录
@GetMapping
公开名单(){
返回scrcrdRepository.findAll();
}
//获取员工的摘要
@GetMapping(value=“{id}”)
公共列表getSummary(@PathVariable字符串id){
返回scrcrdRepository.findAllById(Collections.singleton(id));
}
//按id获取scrcrd记录
@GetMapping(value=“{id}”)
公共Scrcrd get(@PathVariable字符串id){
返回scrcrdRepository.getOne(id);
}
//创建新的SCRRD记录
@邮戳
@ResponseStatus(HttpStatus.CREATED)//获取201个响应,而不是200个响应
公共Scrcrd创建(@RequestBody final Scrcrd-Scrcrd){
返回scrcrdRepository.saveAndFlush(scrcrd);
}
//删除SCRRD记录
@RequestMapping(value=“{id}”,method=RequestMethod.DELETE)
公共无效删除(@PathVariable字符串id){
//删除前还需要检查子记录
scrcrdRepository.deleteById(id);
}
//更新SCRRD记录
@RequestMapping(value=“{id}”,method=RequestMethod.PUT)
公共Scrcrd更新(@PathVariable String id,@RequestBody Scrcrd Scrcrd){
//因为这是一个PUT,所以我们希望所有属性都被传入。补丁只需要修改哪个属性
//TODO:添加所有属性都已传入的验证,否则将返回400错误的负载
Scrcrd existingScrcrd=scrcrdRepository.getOne(id);
//emp的属性被复制到现有SCRRD、emp\u id、mgr\u id、mgr\u scr\u dt,并且类型不被更改
BeanUtils.copyProperties(scrcrd,现有scrcrd,“emp\uuu id”、“经理id”、“经理scr\u dt”、“类型名称”);
返回scrcrdRepository.saveAndFlush(现有scrcrd);
}
}

您已经使用相同的GET请求和端点创建了两个方法,即
/api/v1/scrcrds/{id}
。解决方案是更改其中一个请求的端点*getSummary()或get()。在这里,我更改了
getSummary()
的端点

//获取员工的摘要
@GetMapping(value=“summary/{id}”)
公共列表getSummary(@PathVariable字符串id){
返回scrcrdRepository.findAllById(Collections.singleton(id));
}
//按id获取scrcrd记录
@GetMapping(value=“{id}”)
公共Scrcrd get(@PathVariable字符串id){
返回scrcrdRepository.getOne(id);
}

如果到达的请求与
/api/v1/scrcrds/{id}
匹配,那么应该调用哪个方法,
getSummary
get
?不相关:既然您正在使用and,为什么不使用and?get/api/v1/scrcrds/{id}遇到了两个导致歧义的类似方法。
    //get summary  of an employee
    @GetMapping(value = "summary/{id}")
    public List<Scrcrd> getSummary(@PathVariable String id) {
        return  scrcrdRepository.findAllById(Collections.singleton(id));
    }

    //get scrcrd record by id
    @GetMapping(value = "{id}")
    public Scrcrd get(@PathVariable String id) {
        return scrcrdRepository.getOne(id);
    }