[Spring][쇼핑몰 프로젝트][46] 댓글 등록 - 1

https://kimvampa.tistory.com/288
This commit is contained in:
SeoJin Kim
2022-01-03 15:05:51 +09:00
parent 5266fd2dcd
commit 9f3f678682
17 changed files with 381 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
package com.vam.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vam.model.ReplyDTO;
import com.vam.service.ReplyService;
@RestController
@RequestMapping("/reply")
public class ReplyController {
@Autowired
private ReplyService replyService;
/* 댓글 등록 */
@PostMapping("/enroll")
public void enrollReplyPOST(ReplyDTO dto) {
replyService.enrollReply(dto);
}
}

View File

@@ -0,0 +1,10 @@
package com.vam.mapper;
import com.vam.model.ReplyDTO;
public interface ReplyMapper {
/* 댓글 등록 */
public int enrollReply(ReplyDTO dto);
}

View File

@@ -0,0 +1,75 @@
package com.vam.model;
import java.util.Date;
public class ReplyDTO {
private int replyId;
private int bookId;
private String memberId;
private Date regDate;
private String content;
private double rating;
public int getReplyId() {
return replyId;
}
public void setReplyId(int replyId) {
this.replyId = replyId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public Date getRegDate() {
return regDate;
}
public void setRegDate(Date regDate) {
this.regDate = regDate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
@Override
public String toString() {
return "ReplyDTO [replyId=" + replyId + ", bookId=" + bookId + ", memberId=" + memberId + ", regDate=" + regDate
+ ", content=" + content + ", rating=" + rating + "]";
}
}

View File

@@ -0,0 +1,10 @@
package com.vam.service;
import com.vam.model.ReplyDTO;
public interface ReplyService {
/* 댓글 등록 */
public int enrollReply(ReplyDTO dto);
}

View File

@@ -0,0 +1,24 @@
package com.vam.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.vam.mapper.ReplyMapper;
import com.vam.model.ReplyDTO;
@Service
public class ReplyServiceImpl implements ReplyService{
@Autowired
private ReplyMapper replyMapper;
/* 댓글등록 */
@Override
public int enrollReply(ReplyDTO dto) {
int result = replyMapper.enrollReply(dto);
return result;
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.vam.mapper.ReplyMapper">
<!-- 댓글등록 -->
<insert id="enrollReply">
insert into vam_reply(bookId, memberId, content, rating) values(#{bookId}, #{memberId}, #{content}, #{rating})
</insert>
</mapper>

View File

@@ -0,0 +1,39 @@
package com.vam.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.vam.model.ReplyDTO;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
public class ReplyMapperTests {
@Autowired
private ReplyMapper mapper;
@Test
public void replyEnrollTest() {
String id = "admin";
int bookId = 95;
double rating = 3.5;
String content = "댓글 테스트";
ReplyDTO dto = new ReplyDTO();
dto.setBookId(bookId);
dto.setMemberId(id);
dto.setRating(rating);
dto.setContent(content);
mapper.enrollReply(dto);
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.vam.mapper.ReplyMapper">
<!-- 댓글등록 -->
<insert id="enrollReply">
insert into vam_reply(bookId, memberId, content, rating) values(#{bookId}, #{memberId}, #{content}, #{rating})
</insert>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Dec 29 02:56:42 KST 2021
#Mon Jan 03 13:38:26 KST 2022
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
m2e.projectName=VamPa
groupId=com.vam

View File

@@ -0,0 +1,24 @@
package com.vam.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vam.model.ReplyDTO;
import com.vam.service.ReplyService;
@RestController
@RequestMapping("/reply")
public class ReplyController {
@Autowired
private ReplyService replyService;
/* 댓글 등록 */
@PostMapping("/enroll")
public void enrollReplyPOST(ReplyDTO dto) {
replyService.enrollReply(dto);
}
}

View File

@@ -0,0 +1,10 @@
package com.vam.mapper;
import com.vam.model.ReplyDTO;
public interface ReplyMapper {
/* 댓글 등록 */
public int enrollReply(ReplyDTO dto);
}

View File

@@ -0,0 +1,73 @@
package com.vam.model;
import java.util.Date;
public class ReplyDTO {
private int replyId;
private int bookId;
private String memberId;
private Date regDate;
private String content;
private double rating;
public int getReplyId() {
return replyId;
}
public void setReplyId(int replyId) {
this.replyId = replyId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public Date getRegDate() {
return regDate;
}
public void setRegDate(Date regDate) {
this.regDate = regDate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
@Override
public String toString() {
return "ReplyDTO [replyId=" + replyId + ", bookId=" + bookId + ", memberId=" + memberId + ", regDate=" + regDate
+ ", content=" + content + ", rating=" + rating + "]";
}
}

View File

@@ -0,0 +1,10 @@
package com.vam.service;
import com.vam.model.ReplyDTO;
public interface ReplyService {
/* 댓글 등록 */
public int enrollReply(ReplyDTO dto);
}

View File

@@ -0,0 +1,24 @@
package com.vam.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.vam.mapper.ReplyMapper;
import com.vam.model.ReplyDTO;
@Service
public class ReplyServiceImpl implements ReplyService{
@Autowired
private ReplyMapper replyMapper;
/* 댓글등록 */
@Override
public int enrollReply(ReplyDTO dto) {
int result = replyMapper.enrollReply(dto);
return result;
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.vam.mapper.ReplyMapper">
<!-- 댓글등록 -->
<insert id="enrollReply">
insert into vam_reply(bookId, memberId, content, rating) values(#{bookId}, #{memberId}, #{content}, #{rating})
</insert>
</mapper>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.vam.mapper.ReplyMapper">
<!-- 댓글등록 -->
<insert id="enrollReply">
insert into vam_reply(bookId, memberId, content, rating) values(#{bookId}, #{memberId}, #{content}, #{rating})
</insert>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Dec 29 02:56:42 KST 2021
#Mon Jan 03 13:38:26 KST 2022
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
m2e.projectName=VamPa_MySQL
groupId=com.vam