1. 程式人生 > 實用技巧 >Ambiguous mapping. Cannot map 'xxxController' method

Ambiguous mapping. Cannot map 'xxxController' method

  @GetMapping
    public JsonResp<List<DtoLandRegion>> getLandRegionList() {
        List<DtoLandRegion> regions = service.getLandRegionList();
        return JsonResp.newSuccessResp(regions);
    }

    @GetMapping
    public JsonResp<List<DtoFactorType>> getFactorTypeList() {
        List
<DtoFactorType> factors = service.getFactorTypeList(); return JsonResp.newSuccessResp(factors); }

上面的程式碼中,都有@GetMapping,並沒有指定value值,所以重複了,導致對映模糊。

解決方法,指定value值。

    @GetMapping("/getLandRegionList")
    public JsonResp<List<DtoLandRegion>> getLandRegionList() {
        List
<DtoLandRegion> regions = service.getLandRegionList(); return JsonResp.newSuccessResp(regions); } @GetMapping("/getFactorTypeList") public JsonResp<List<DtoFactorType>> getFactorTypeList() { List<DtoFactorType> factors = service.getFactorTypeList();
return JsonResp.newSuccessResp(factors); }

問題就可以解決啦!