티스토리 뷰
In this post, i just made a super beginner project using JpaRepository.
Before we start, let me tell the version and dependency in this project.
🟩 Version and Dependency in this project
(Version)
- Spring Boot : 4.0.1
- java : 21
- Packaging : Jar
- Confiquration : YAML, Gradle-groovy
(Dependency)
- Spring Web
- Spring Data Jpa
- H2 Database
- Lombok
🟩 Project Descirption

(It's really simple haha)
This is a project structure of this post.
I just want to build a blog application(?), so i tried this.
In this project, we will make 4 functions, saving article, fetch all article, updating article, deleting article.
🟩 Implementation project
At first, create a Entity that named as Article.
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank
private String title;
@NotBlank
private String content;
}
And, create a Repository.
@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {
//
}
In this post, i will not deep dive into "how to use JpaRepository".
I will get into it later!! for more bigger project soon!
And create Service.
I seperate service code by using interface.
I think, when i add more Entity, i will use methods for that Entity same with Article Entiry.
So, i use interface so that i can lay the foundation.
@org.springframework.stereotype.Service
public interface Service {
Article save(Article article);
List<Article> fetchAll();
Article update(Long id, Article article);
void delete(Long id);
}
@org.springframework.stereotype.Service
public class ServiceImpl implements Service {
private ArticleRepository articleRepository;
@Autowired
public ServiceImpl(ArticleRepository articleRepository) {
this.articleRepository = articleRepository;
}
@Override
public Article save(Article article) {
return articleRepository.save(article);
}
@Override
public List<Article> fetchAll() {
return articleRepository.findAll();
}
@Override
public Article update(Long id, Article articleForUpdate) {
Article article = articleRepository.findById(id).get(); // FIXME
article.setTitle(articleForUpdate.getTitle());
article.setContent(articleForUpdate.getContent());
return articleRepository.save(article);
}
@Override
public void delete(Long id) {
articleRepository.deleteById(id);
}
}
And finally, Controller code.
@RestController
public class Controller {
private Service service;
@Autowired
public Controller(Service service) {
this.service = service;
}
@PostMapping("/article")
public Article save(
@Valid @RequestBody Article article
) {
return service.save(article);
}
@GetMapping("/article")
public List<Article> fetchAll() {
return service.fetchAll();
}
@PutMapping("/article/{id}")
public Article updateContent(
@PathVariable Long id,
@Valid @RequestBody Article article
) {
return service.update(id, article);
}
@DeleteMapping("/article/{id}")
public void delete(
@PathVariable Long id
) {
service.delete(id);
}
}
okay.
Let's execute it!
🟩 Request with Postman!!
🟦 Save a article



Now, we've saved three articles here.
🟦 fetch all articles

🟦 Update a article by id.
I updated the content, "eat proteins" from "try pushUp and pullUp", at the id-2 article.


🟦 Delete article by id
I deleted article, id-1.


That's it.
Of course, there is a lot of problems (Not use DTO, using getter at the service layer etc.....).
So, project, i will make a more upgraded project than this...
---------------------------------------
I'm an university student soon.........................!!!!!
reference)
https://www.geeksforgeeks.org/springboot/spring-boot-jparepository-with-example/
Spring Boot JpaRepository with Example - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
www.geeksforgeeks.org
'코딩 프로젝트 & 설계' 카테고리의 다른 글
| 의존한다 표현 이해하기 (0) | 2026.03.29 |
|---|---|
| 초딩 마리오 ppt 퀴즈 게임 만들기 (0) | 2026.02.13 |
| instanceof 및 다운 캐스팅 활용 - 부모 클래스와 자식 클래스 공통 메서드 문제 - 부모 타입의 배열에 있던 자식 객체를 불러왔는데, 해당 자식 객체에서 사용하려는 메서드가 부모 타입에 있는 메서드(공통메서드)가 아닌, 해당 자식 객체에서만 있는 기능인 경우 해결법. (0) | 2025.11.24 |
| new 프로젝트 계획!! ( 2025/11/06 ) (0) | 2025.11.06 |
| 도메인 객체의 유효성 검사, 어디서 해야할까? (0) | 2025.10.07 |