I have a simple controller in Spring Boot application
@GetMapping("/")
public Page<StockDto> listStocks(Pageable pageable) {
return stockService.list(pageable);
}
It calls list
method in StockService
to get a list of items from the database. StockRepository is a class that extends JpaRepository with a @Repository
annotation.
@Service
public class StockService {
private StockRepository stockRepository;
private ModelMapper modelMapper;
@Autowired
public StockService(StockRepository stockRepository, ModelMapper modelMapper) {
this.stockRepository = stockRepository;
this.modelMapper = modelMapper;
}
public Page<StockDto> list(Pageable pageable) {
Page<StockEntity> stockEntities = stockRepository.findAll(pageable);
return stockEntities.map(stockEntity -> modelMapper.map(stockEntity, StockDto.class));
}
}
The JSON result of calling API has content
, pageable
, and some other fields.
I didn't use Spring Data Rest
too. Now I want to add two Next and Prev strings that have next and previous links of getting resource in response JSON.