MyPage에 내가 쓴 후기글과
Main에 최신순으로 업데이트된 4개의 후기글을 화면에 보여줄수 있게 연동을 구현하였다
먼저 로그인된 id :"dodo" 로 후기글을 등록하고,
MySQL Workbench에서 dodo 가 쓴 글만 출력되는지 DB를 확인하였다
SELECT *
FROM review
where memId="dodo"
ORDER BY reviewNo;
ReviewMapper
출력된 후기글을 spring Framwork에서 출력될수 있게 mapping하였다.
<!-- 마이 페이지 -->
<!-- 내가 쓴 후기 -->
<select id="reviewMypage" parameterType="String" resultMap="reviewResult">
SELECT *
FROM review
where memId=#{memId}
</select>
<!-- Main 페이지 -->
<!-- 최신순 3개 출력 -->
<select id="listRecentReview" resultMap="reviewResult">
SELECT *
FROM review
ORDER BY reviewNo DESC LIMIT 0,4
</select>
ReviewServiceServiece
package com.Me_and_U.project.service;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.Me_and_U.project.dao.IReviewDAO;
import com.Me_and_U.project.model.ReviewVO;
@Service
public class ReviewService implements IReviewService {
@Autowired
@Qualifier("IReviewDAO")
IReviewDAO dao;
// 마이페이지출력
@Override
public ArrayList<ReviewVO> reviewMypage(String memId) {
return dao.reviewMypage(memId);
}
// 최신순
@Override
public ArrayList<ReviewVO> listRecentReview() {
return dao.listRecentReview();
}
}
IReviewService와 IReviewDAO
package com.Me_and_U.project.service;
import java.util.ArrayList;
import com.Me_and_U.project.model.ReviewVO;
public interface IReviewService {
public ArrayList<ReviewVO> listRecentReview(); //최신순
public ArrayList<ReviewVO> reviewMypage(String memId); //마이페이지 후기
}
package com.Me_and_U.project.dao;
import java.util.ArrayList;
import com.Me_and_U.project.model.ReviewVO;
public interface IReviewDAO {
public ArrayList<ReviewVO> listRecentReview(); //최신순 3개
public ArrayList<ReviewVO> reviewMypage(String memId); //마이페이지 후기
}
ReviewVO 에서 타입지정 후 get,set 해주고
ReviewController
package com.Me_and_U.project.controller;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.Me_and_U.project.model.ReviewVO;
import com.Me_and_U.project.service.ReviewService;
@Controller
public class ReviewController {
@Autowired
ReviewService service;
//http://localhost:8080/listRecentReview
//최신순
@RequestMapping("/listRecentReview")
public String listRecentReview(Model model) {
ArrayList<ReviewVO> reviewRec = service.listRecentReview();
model.addAttribute("reviewRec",reviewRec);
return "jsp/reviewPlus";
}
//http://localhost:8080/reviewMypage
//마이페이지 자신이 등록한 후기글 불러오기
@RequestMapping("/reviewMypage")
public String reviewMypage(Model model,HttpSession session) {
String memId = (String) session.getAttribute("sid");
ArrayList<ReviewVO> reviewMy = service.reviewMypage(memId);
model.addAttribute("reviewMy",reviewMy);
return "jsp/reviewMypage";
}
폼데이터에 값 출력해주기
'Project' 카테고리의 다른 글
| 프로젝트 수행 계획 및 현황 3주차 (0) | 2023.01.17 |
|---|