## 반복주기 5 학습 목표
* 객체 간의 관계 설정(@OneToMany, @ManyToOne 등)
## 강의 순서
* 5-1. 회원과 질문 간의 관계 매핑 및 리팩토링
* 5-2. 질문 상세보기 기능 구현
* 5-3. 질문 수정 기능 구현
* 5-4. 답변 추가 및 답변 목록 기능 구현
* 5-5. 원격 서버에 소스 코드 배포
class Question
package net.slipp.domain;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
public class Question {
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JoinColumn(foreignKey=@ForeignKey(name="fk_question_writer"))
private User writer;
private String title;
private String contents;
@Temporal(TemporalType.TIMESTAMP)
private Date datetime;
public Question() {
}
public Question(User writer, String title, String contents) {
this.datetime = new Date();
this.writer = writer;
this.title = title;
this.contents = contents;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getWriter() {
return writer;
}
public void setWriter(User writer) {
this.writer = writer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
public Date getDatetime() {
return datetime;
}
public void setDatetime(Date datetime) {
this.datetime = datetime;
}
@Override
public String toString() {
return "Question [id=" + id + ", writer=" + writer + ", title=" + title + ", contents=" + contents
+ ", datetime=" + datetime + "]";
}
}
index.html
{{> include/header}}
{{> include/navigation}}
<div class="container" id="main">
<div class="col-md-12 col-sm-12 col-lg-10 col-lg-offset-1">
<div class="panel panel-default qna-list">
<ul class="list">
{{^ questions}}
<li>
<div class="wrap">
<div class="main text-center">
등록된 글이 없습니다.
</div>
</div>
</li>
{{/questions}}
{{#questions}}
<li>
<div class="wrap">
<div class="main">
<strong class="subject">
<a href="./qna/show.html">{{title}}</a>
</strong>
<div class="auth-info">
<i class="icon-add-comment"></i>
<span class="time">{{datetime}}</span>
<a href="./user/profile.html" class="author">{{writer}}</a>
</div>
<div class="reply" title="댓글">
<i class="icon-reply"></i>
<span class="point">8</span>
</div>
</div>
</div>
</li>
{{/questions}}
</ul>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6 text-center">
<ul class="pagination center-block" style="display:inline-block;">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
</div>
<div class="col-md-3 qna-write">
<a href="./qna/form.html" class="btn btn-primary pull-right" role="button">질문하기</a>
</div>
</div>
</div>
</div>
</div>
<!--login modal-->
<!--
<div id="loginModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="text-center"><img src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=100" class="img-circle"><br>Login</h2>
</div>
<div class="modal-body">
<form class="form col-md-12 center-block">
<div class="form-group">
<label for="userId">사용자 아이디</label>
<input class="form-control" name="userId" placeholder="User ID">
</div>
<div class="form-group">
<label for="password">비밀번호</label>
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg btn-block">로그인</button>
<span class="pull-right"><a href="#registerModal" role="button" data-toggle="modal">회원가입</a></span>
</div>
</form>
</div>
<div class="modal-footer">
<div class="col-md-12">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
</div>
</div>
</div>
</div>
-->
<!--register modal-->
<!--
<div id="registerModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="text-center"><img src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=100" class="img-circle"><br>회원가입</h2>
</div>
<div class="modal-body">
<form class="form col-md-12 center-block">
<div class="form-group">
<label for="userId">사용자 아이디</label>
<input class="form-control" id="userId" name="userId" placeholder="User ID">
</div>
<div class="form-group">
<label for="password">비밀번호</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<div class="form-group">
<label for="name">이름</label>
<input class="form-control" id="name" name="name" placeholder="Name">
</div>
<div class="form-group">
<label for="email">이메일</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg btn-block">회원가입</button>
</div>
</form>
</div>
<div class="modal-footer">
<div class="col-md-12">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
</div>
</div>
</div>
</div>
-->
{{> include/footer}}
댓글 ( 4)
댓글 남기기