Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/web/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BoardController(BoardService boardService) {

@GetMapping({"", "/"})
public String board(@RequestParam(value = "idx", defaultValue = "0") Long idx, Model model) {
model.addAttribute("board", boardService.findBoardByIdx(idx));
model.addAttribute("board", boardService.findBoardByIdx(idx).orElse(null));
return "/board/form";
}

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/web/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.*;

import lombok.Builder;
import lombok.Getter;
Expand All @@ -30,7 +22,7 @@ public class Board implements Serializable {

@Id
@Column
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idx;

@Column
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/web/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;

import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,7 +20,7 @@ public class User implements Serializable {

@Id
@Column
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idx;

@Column
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/web/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* Created by KimYJ on 2017-07-13.
*/
Expand All @@ -24,8 +26,8 @@ public Page<Board> findBoardList(Pageable pageable) {
return boardRepository.findAll(pageable);
}

public Board findBoardByIdx(Long idx) {
return boardRepository.getOne(idx);
public Optional<Board> findBoardByIdx(Long idx) {
return boardRepository.findById(idx);
}

public Board saveAndUpdateBoard(Board board) {
Expand Down