@RestController
@RequiredArgsConstructor
public class BoardController {
private final BoardService boardService;
@PostMapping("/api/add")
public Board addBoard(@RequestBody BoardRequestDto boardRequestDto){
return boardService.addBoard(boardRequestDto);
}
}
@Service
@RequiredArgsConstructor
public class BoardService {
private final BoardRepository boardRepository;
@Transactional
public Board addBoard(BoardRequestDto boardRequestDto) {
Board board = new Board(boardRequestDto);
boardRepository.save(board);
return board;
}
}
public interface BoardRepository extends JpaRepository<Board,Long> {
List<Board> findAllByOrderByCreatedAtDesc();
}
https://velog.io/@jybin96/Controller-Service-Repository-%EA%B0%80-%EB%AC%B4%EC%97%87%EC%9D%BC%EA%B9%8C
https://velog.io/@daydream/Spring-Controller-Service-Repository-DAO
https://velog.io/@kimdy0915/Spring-Controller-Service-Repository%EB%A5%BC-%EC%95%8C%EC%95%84%EB%B3%B4%EC%9E%90