抽象类和url映射

时间:2017-07-25 12:54:37

标签: spring spring-restcontroller request-mapping

我有一个抽象类

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

我遇到有关制图的问题。

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;
    }

我可以致电

/休息/ VEHICULES / 1

但我得到404

/休息/ VEHICULES

1 个答案:

答案 0 :(得分:1)

问题在于你的附加“/”,这意味着你的网址将是“/ rest / vehicules /”

您只需要@GetMapping

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