Я чувствую, что это должно быть довольно просто, но я не уверен насчет реального кода для него. По сути, мой контроллер покоя принимает 6 аргументов, передает их через Сервис, а затем использует эти аргументы для построения объекта внутри ServiceImplementation. Оттуда я возвращаю вызов в мой репо, используя только что сделанный объект. Этот вызов должен попытаться запросить базу данных, указав c параметры объекта.
В этом запросе я не уверен, как писать, используя стандарты Spring JPA. Я хотел бы просто использовать переменные, для которых я установил свой объект, но я не уверен, придется ли мне выписывать запрос или если Spring JPA может сделать его немного проще?
Код :
Контроллер:
@RestController
public class exampleController {
@Autowired
private ExampleService exampleService;
@GetMapping("/rest/example/search")
public exampleObj searchExample (@RequestParam(value = "exLetter") String exLetter,
@RequestParam(value = "exLang") String exLang, @RequestParam(value = "exType")int exType,
@RequestParam(value = "exMethod") String exMethod, @RequestParam(value = "exCd") String exCd,
@RequestParam(value = "exOrg") String exOrg) {
return exampleService.getExampleLetter(exLetter, exLang, exType, exMethod, exCd, exOrg);
}
}
ExampleSerivce:
public interface ExampleService {
public ExampleLetter getExampleLetter(String exLetter, String exLang, int exType, String exMethod, String exCd, String exOrg);
}
ExampleServiceImplementation:
@Service
public class ExampleServiceImpl implements ExampleService {
@Autowired
private ExampleRepository exampleRepo;
@Override
public ExampleLetter getExampleLetter(String exLetter, String exLang, int exType, String exMethod, String exCd, String exOrg) {
ExampleLetter examp = new ExampleLetter();
examp.setExCd(exCd);
examp.getKey().setExampleNumber(exLetter);
examp.getKey().setLanguageType(exLang);
examp.getKey().setMethod(exMethod);
examp.getKey().setMarketOrg(exOrg);
examp.getKey().setType(exType);
return exampleRepo.findExampleLetter(examp);
}
}
Репо:
@Repository
public interface ExampleRepository extends CrudRepository<ExampleLetter, ExampleLetterKey> {
}