반응형
2021년 10월 3일 글
스프링 프로젝트 세팅 순서
dto >> mapper >> dao >> service >> 예외처리
1. dto
- 게시판 dto
공지사항, 이용후기, qna 세개의 게시판을 만들 예정이다
1) 게시글 Post dto
post.java
package dto;
public class Post {
private String id;
private String user_id;
private String title;
private String content;
private String post_date;
private int hit;
public Post() {
// TODO Auto-generated constructor stub
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPost_date() {
return post_date;
}
public void setPost_date(String post_date) {
this.post_date = post_date;
}
public int getHit() {
return hit;
}
public void setHit(int hit) {
this.hit = hit;
}
}
2) 답글 Reply dto
reply.java
package dto;
public class Reply {
private String id;
private String post_id;
private String user_id;
private String content;
private String reply_date;
public Reply() {
// TODO Auto-generated constructor stub
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPost_id() {
return post_id;
}
public void setPost_id(String post_id) {
this.post_id = post_id;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getReply_date() {
return reply_date;
}
public void setReply_date(String reply_date) {
this.reply_date = reply_date;
}
}
- 돌봄일지 dto
dolbom.java
package dto;
public class Dolbom {
private String id;
private String reservation_id;
private String sitter_id;
private String title;
private String img;
private String content;
private String post_date;
private String update_date;
public Dolbom() {
// TODO Auto-generated constructor stub
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getReservation_id() {
return reservation_id;
}
public void setReservation_id(String reservation_id) {
this.reservation_id = reservation_id;
}
public String getSitter_id() {
return sitter_id;
}
public void setSitter_id(String sitter_id) {
this.sitter_id = sitter_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPost_date() {
return post_date;
}
public void setPost_date(String post_date) {
this.post_date = post_date;
}
public String getUpdate_date() {
return update_date;
}
public void setUpdate_date(String update_date) {
this.update_date = update_date;
}
}
2. mapper : 인터페이스와 xml 파일
- 게시판 mapper : post, reply
post와 reply 각각 인터페이스 파일과 xml 파일을 만들어준다!
1) 게시글 Post mapper
PostMapper.java - 인터페이스
package mapper;
import java.util.List;
import dto.Post;
public interface PostMapper {
int insertPost(Post post);
int updatePost(Post post);
int deletePost(String id);
Post selectPost(String id);
List<Post> selectPostList(String userId);
}
PostMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.PostMapper">
<insert id="insertPost">
insert into post values(#{id}, #{userId},
#{title}, #{content}, #{postDate}, #{hit})
</insert>
<update id="updatePost">
update post
<set>
<if test="userId!=null and userId!=''">
user_id=#{userId},
</if>
<if test="title!=null and title!=''">
title = #{title},
</if>
<if test="content!=null and content!=''">
content=#{content}
</if>
<if test="post_date!=null and post_date!=''">
post_date = #{postDate}
</if>
</set>
where id=#{id}
</update>
<delete id="deletePost">
delete from post where id = #{id}
</delete>
<select id="selectPost" resultType="Post">
select * from post where id = #{id}
</select>
<select id="selectPostList" resultType="Post">
select * from post where user_id = #{userId}
</select>
</mapper>
2) 답글 Reply mapper
ReplyMapper.java - 인터페이스
package mapper;
import java.util.List;
import dto.Reply;
public interface ReplyMapper {
int insertReply(Reply reply);
int updateReply(Reply reply);
int deleteReply(String id);
Reply selectReply(String id);
List<Reply> selectPostReplyList(String postId);
List<Reply> selectUserReplyList(String userId);
}
ReplyMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.ReplyMapper">
<insert id="insertReply">
insert into reply values(#{id}, #{postId}, #{userId},
#{content}, #{replyDate})
</insert>
<update id="updateReply">
update reply
<set>
<if test="content!=null and content!=''">
content=#{content}
</if>
<if test="reply_date!=null and reply_date!=''">
reply_date = #{replyDate}
</if>
</set>
where id=#{id}
</update>
<delete id="deleteReply">
delete from reply where id = #{id}
</delete>
<select id="selectReply">
select * from reply where id = #{id}
</select>
<select id="selectPostReplyList">
select * from post where post_id = #{postId}
</select>
<select id="selectUserReplyList">
select * from post where user_id = #{userId}
</select>
</mapper>
- 돌봄일지 mapper
dolbomMapper.java - 인터페이스
package mapper;
import java.util.List;
import dto.Dolbom;
public interface DolbomMapper {
int insertDolbom(Dolbom dolbom);
int updateDolbom(Dolbom dolbom);
Dolbom selectDolbom(String id);
List<Dolbom> selectDolbomList(String reservationId);
List<Dolbom> selectSitterDolbomList(String sitterId);
}
dolbomMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.DolbomMapper">
<insert id="insertDolbom">
insert into dolbom values (#{id}, #{reservationId}, #{sitterId}
, #{title}, #{img}, #{content}, #{postDate}, #{updateDate})
</insert>
<update id="">
update dolbom
<set>
<if test="title!=null and title!=''">
title = #{title},
</if>
<if test="img!=null and img!=''">
img = #{img},
</if>
<if test="content!=null and content!=''">
content=#{content}
</if>
<if test="update_date!=null and update_date!=''">
update_date = #{updateDate}
</if>
</set>
where id = #{id}
</update>
<select id="selectDolbom" resultType="Dolbom">
select * from dolbom where id = #{id}
</select>
<select id="selectDolbomList" resultType="Dolbom">
select * from dolbom where reservation_id = #{reservationId}
</select>
<select id="selectSitterDolbomList" resultType="Dolbom">
select * from dolbom where sitter_id = #{sitterId}
</select>
</mapper>
반응형
'프로젝트 기록 > semi, final project' 카테고리의 다른 글
파이널 프로젝트 - 스프링 세팅 4-2. dao, service (0) | 2023.10.24 |
---|---|
파이널 프로젝트 - 3. 예약사이트 DB (0) | 2023.10.24 |
파이널 프로젝트 - 2. 예약사이트 기능 파악 및 기능 구현 (0) | 2023.10.24 |
파이널 프로젝트 - 1. 주제 정하기 (0) | 2023.10.24 |
파이널 프로젝트 - Spring 프로젝트 환경설정 (ft.이클립스) (0) | 2023.10.23 |