Контроллер имеет следующий код:
Код: Выделить всё
@RestController
@RequestMapping("/journal")
public class JournalEntryControllerV2 {
@Autowired
private JournalEntryService journalEntryService;
@GetMapping
public List getAll() {
return journalEntryService.getAll();
}
@PostMapping
public JournalEntry createEntry(@RequestBody JournalEntry myEntry) {
myEntry.setDate(LocalDateTime.now());
journalEntryService.saveEntry(myEntry);
return myEntry;
}
Код: Выделить всё
package com.engineeringdigest.journalApp.services;
import com.engineeringdigest.journalApp.entity.JournalEntry;
import com.engineeringdigest.journalApp.repository.JournalEntryRepository;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
@Component
public class JournalEntryService {
@Autowired
private JournalEntryRepository journalEntryRepository;
public void saveEntry (JournalEntry journalEntry) {
journalEntryRepository.save(journalEntry);
}
public List getAll(){
return journalEntryRepository.findAll();
}
public Optional findByID(ObjectId id) {
return journalEntryRepository.findById(id);
}
public void deleteById(ObjectId id) {
journalEntryRepository.deleteById(id);
}
}
//Controller -----> Service ------>repo
Может кто-нибудь помочь.
Post Man-
введите здесь описание изображения
p>
Я пытался интегрировать MongoDB + SpringBoot. Следующий контроллер -> сервис -> практика репо.
Подробнее здесь: https://stackoverflow.com/questions/790 ... -and-sprin