Это не очень понятно для меня, но если вы используете весеннюю загрузку, вы, конечно, можете создать контроллер, сервис и репозиторий или dao.
Действительно, ваш диспетчер позвонит вашему сервису, который вызовет хранилище.
Предположим, что у вас есть клиент, который вызывает ваш API.
Так звонок будет выглядеть так:
// Suppose that is a spring boot project
Class A {
@Autowired
RestTemplate restTemplate;
public void create(){
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType((MediaType.APPLICATION_JSON));
headers.add("X-yourCustom-context", "yourCustom");
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(your_service_url)
.queryParam("params1", "value".queryParam("params2", value2));
HttpEntity<?> entity = new HttpEntity<>(headers);
restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, null); // if you want to return an objectr you put it rather than the null
}
}
API услуги:
@RestController
public class YourController {
@Autowired
private YourService service;
@Autowired
private ObjectMapper objectMapper;
@PostMapping(value = "/bills")
//@ResponseBody if you do not return any think you can not use it
// @CrossOrigin if you want to call your reste from an external project like javascript or angular
//@Transactional you can put it on the top of your service methode
public void createBill(@RequestParam(value = "params1", required = true) String params1,
@RequestParam(value = "params2", required = true) String params2,
@RequestHeader(value = "X-yourCustom-context", required = true) String yourContxt) throws IOException {
// You can then convert your x-context to an object that you have already by using objectMapper.readValue
// Finaly you call you service to create the bill and you passe as params what you get fron the client
}
}
Я надеюсь, что это отвечает вашим потребностям:)