@Override public List<Comment> listComment(Pagination page) { String sql = "SELECT CM.*, V.videoname, U.username, U.userimageurl " + "FROM TBLCOMMENT CM " + "INNER JOIN TBLVIDEO V ON CM.videoid=V.videoid " + "INNER JOIN TBLUSER U ON CM.userid=U.userid " + "ORDER BY commentdate DESC OFFSET ? LIMIT ?"; List<Comment> list = new ArrayList<Comment>(); Comment comment = null; try (Connection cnn = dataSource.getConnection(); PreparedStatement ps = cnn.prepareStatement(sql); ) { ps.setInt(1, page.offset()); ps.setInt(2, page.getItem()); ResultSet rs = ps.executeQuery(); while (rs.next()) { comment = new Comment(); comment.setCommentId(Encryption.encode(rs.getString("commentid"))); comment.setCommentDate(rs.getDate("commentdate")); comment.setCommentText(rs.getString("commenttext")); comment.setVideoId(Encryption.encode(rs.getString("videoid"))); comment.setUserId(Encryption.encode(rs.getString("userid"))); comment.setVideoName(rs.getString("videoname")); comment.setUsername(rs.getString("username")); comment.setUserImageUrl(rs.getString("userimageurl")); comment.setReplyId(Encryption.encode(rs.getString("replycomid"))); list.add(comment); } return list; } catch (SQLException e) { e.printStackTrace(); } return null; }
// Get List comment with comment text: param(commentText,offset,limit) @RequestMapping( method = RequestMethod.GET, value = "/comment/reply/list/v/{videoId}/r/{replyId}", headers = "Accept=application/json") public ResponseEntity<Map<String, Object>> getListReplyComment( @RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "item", required = false, defaultValue = "10") int item, @PathVariable("videoId") String videoId, @PathVariable("replyId") String replyId) { Map<String, Object> map = new HashMap<String, Object>(); try { Pagination pagination = new Pagination(); pagination.setItem(item); pagination.setPage(page); pagination.setTotalCount(commentService.countReplyComment(videoId, replyId)); pagination.setTotalPages(pagination.totalPages()); List<Comment> comment = commentService.listReplyComment(videoId, replyId, pagination); if (comment.isEmpty()) { map.put("STATUS", false); map.put("MESSAGE", "RECORD NOT FOUND"); } else { map.put("STATUS", true); map.put("MESSAGE", "RECORD FOUND"); map.put("RES_DATA", comment); map.put("PAGINATION", pagination); } } catch (Exception e) { map.put("MESSAGE", "OPERATION FAIL"); map.put("STATUS", false); } return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK); }