摘要 class 和 url 映射

Abstract class and url mapping

我有一个摘要class

我尝试在这个 class 中使用所有泛型方法。

我遇到关于映射的问题。

public abstract class BaseControllerNew<T extends BaseEntity, R extends BaseDto, S extends BaseSearch> {
    ...
    @GetMapping(value = "/{id}")
    public R getById(@PathVariable("id") Integer id){
        return baseServiceNew.getById(id);
    }

    @GetMapping(value = "/")
    public Page<R> get(Pageable page){
        return baseServiceNew.get(page);
    }
    ....
}


@RequestMapping(value = "/rest/vehicules")
@RestController
public class VehiculesRestController extends BaseControllerNew<Vehicules, VehiculesDto, VehiculesSearch>{

    private VehiculesServiceImpl vehiculesService;

    @Autowired
    public VehiculesRestController(final VehiculesServiceImpl vehiculesService) {
        super(vehiculesService);
        this.vehiculesService = vehiculesService;
    }

我可以打电话

/rest/vehicules/1

但我得到 404

/rest/vehicules

问题出在你额外的“/”上,这意味着你的 URL 将是“/rest/vehicules/”

你只需要@GetMapping

 @GetMapping
public Page<R> get(Pageable page){
    return baseServiceNew.get(page);
}