728x90
BoardService.java
package com.example.board.service;
import com.example.board.entity.Board;
import com.example.board.repository.BoardRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Service
public class BoardService {
@Autowired
private BoardRepository boardRepository;
// 글 작성 처리
public void write(Board board){
boardRepository.save(board);
}
// 게시물 리스트 처리
public List<Board> boardList(){
return boardRepository.findAll();
}
//특정 게시물 불러오기
public Board boardView(Integer id){
return boardRepository.findById(id).get();
}
// 특정 게시물 삭제
public void boardDelete(Integer id){
boardRepository.deleteById(id);
}
}
BoardService.java
package com.example.board.service;
import com.example.board.entity.Board;
import com.example.board.repository.BoardRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Service
public class BoardService {
@Autowired
private BoardRepository boardRepository;
// 글 작성 처리
public void write(Board board){
boardRepository.save(board);
}
// 게시물 리스트 처리
public List<Board> boardList(){
return boardRepository.findAll();
}
//특정 게시물 불러오기
public Board boardView(Integer id){
return boardRepository.findById(id).get();
}
// 특정 게시물 삭제
public void boardDelete(Integer id){
boardRepository.deleteById(id);
}
}
boardview.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>게시글 상세 페이지</title>
</head>
<body>
<h1 th:text="${board.title}">제목입니다.</h1>
<p th:text="${board.content}">내용이 들어갈 부분입니다.</p>
<a th:href="@{/board/delete(id=${board.id})}"> 글삭제 </a>
</body>
</html>
728x90
'개발&etc > Spring boot' 카테고리의 다른 글
[Spring Boot] spring/springboot 공부 자료 모음 (0) | 2023.04.25 |
---|---|
[Tomcat]Server Tomcat v9.0 Server at localhost failed to start. (0) | 2023.03.16 |
[Tomcat] Several ports (8005, 8080, 8009) required by Tomcat v9.0 Server at localhost are already in use. (0) | 2023.03.16 |
[스프링] 스프링 입문 - 코드로 배우는 스프링 부트, 회원관리 예제 (0) | 2023.02.15 |
[스프링] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 (2) | 2023.02.15 |