20240220 댓글 입력창 =스크립트로 빈칸검사하기
form태그 안에 onsubmit 추가하기.
textarea태그 안에 id 추가하기
<hr>
<!-- 댓글 입력창 = 스크립트로 빈칸검사하기 -->
<div class="">
<form action="./commentWrite" method="post" onsubmit="return commentInsert()">
<div class="row">
<div class="input-group mb-3">
<textarea class="form-control" id="comment" name="comment"
aria-describedby="comment-input"></textarea>
<button class="btn btn-secondary" type="submit" id="comment-input">댓글쓰기</button>
</div>
</div>
<input type="hidden" name="no" value="${detail.board_no }">
</form>
</div>
function 만들어주기.
//20240220 댓글 입력창 =스크립트로 빈칸검사하기
function commentInsert(){
let comment = $("#comment").val();
if (comment.length < 10){
Swal.fire("댓글의 길이가 짧습니다.", "댓글은 10글자 이상이어야 합니다.", "warning");
return false;
}
}
댓글 글자수 제이쿼리 만들어주기
//jquery start
$(function(){
// 댓글쓰기 몇 글자 썼는지 확인하는 코드 2024-02-20 psd
$("#comment").keyup(function(){
let text = $(this).val();
if (text.length > 500){
Swal.fire("댓글의 길이가 깁니다", "댓글은 500자 까지 가능합니다.", "warning");
$(this).val(text.substr(0, 500));
}
$("#comment-input").text("댓글쓰기 " + text.length + "/500");
});
});
글 삭제하기
detail.jsp
function deletePost(){
Swal.fire({
title: "글을 삭제하시겠습니까?",
//text: "post를 삭제합니다.",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Yes",
cancelButtonText: "No",
}).then(result => {
if (result.isConfirmed) {
//java에게 삭제하라고 명령내리겠습니다.
//가상 form = post
let vform = $('<form></form>');
vform.attr('name', 'vform');
vform.attr('method', 'post');
vform.attr('action', './postDel');
vform.append($('<input/>', {type:'hidden', name:'no', value:${detail.board_no } }));
vform.appendTo('body');
vform.submit();
//Swal.fire("삭제했습니다.","", "success");
}//end if
});//end deletePost()
}
BoardController.java > postDel 만들기
@PostMapping("/postDel")
public String postDel(@RequestParam("no") int no) {
int result = boardService.postDel(no);
// System.out.println("no : " + no);
return "redirest:/board";
BoardService> 메소드 만들러가기
//2024.02.20
public int postDel(int no) {
return boardDAO.postDel(no);
}
BoardDAO> postDel(int) 만들러가기
public int postDel(int no) {
return sqlSession.update("board.postDel",no);
}
}
board-mapping.xml
<!--2024.02.20 -->
<update id="postDel" parameterType="Integer">
UPDATE board SET board_del='0' WHERE board_no=#{no}
</update>
CDATA 사용하기>순수하게 SQL 명령으로 봐야한다. 태그 시작, 태그 끝 아니다
<!--2024.02.20 -->
<update id="postDel" parameterType="Integer">
<![CDATA[
UPDATE board SET board_del='0' WHERE board_no=#{no}
]]>
</update>
페이징하기
전자정부 페이징
https://www.egovframe.go.kr/wiki/doku.php?id=egovframework:rte:ptl:view:paginationtag
빈설정하기
pom.xml> 전자정부 관련된 것 있는지
<bean id="textRenderer" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationRenderer">
</bean>
<bean id="imageRenderer" class="org.mask.util.ImagePaginationRenderer"> </bean>
<bean id="pagiationManager" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationRenderer"
<property name="rendererType">
<map>
<entry key="text" value-ref="textRenderer"></entry>
<entry key="imge" value-ref="imgRenderer"></entry>
</map>
</property>
</beans>
서비스
에이
시발
ㅡㅅㅡ
포스트 삭제부터 되지 않음
페이징 추가
// 2024.02.20 페이징 추가하기
@GetMapping("/board")
public String board(@RequestParam(value = "pageNo", required = false) String no, Model model) {
// pageNo가 오지 않는다면
int currentPageNo = 1;
if (util.str2Int(no) > 0) { // 정수=1, 정수가 아니면 currentPageNo
currentPageNo = Integer.parseInt(no);
}
// 2024.02.20 전체 글 수 totalRecordCount (0, 1인 것들만 가져오기)
int totalRecordCount = boardService.totalRecordCount();
// System.out.println("totalRecordCount : "+totalRecordCount);
// pagination
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(currentPageNo); // 현재 페이지 번호
paginationInfo.setRecordCountPerPage(10); // 한 페이지에 게시되는 게시물 수
paginationInfo.setPageSize(10); // 페이징 리스트의 사이즈 (페이징 숫자 수)
paginationInfo.setTotalRecordCount(totalRecordCount); // 전체 게시물 건 수
List<BoardDTO> list = boardService.boardList(paginationInfo.getFirstRecordIndex()); // boardList -> change
// method
model.addAttribute("list", list);
// 페이징 관련 정보가 있는 PaginationInfo 객체를 모델에 반드시 넣어준다.
model.addAttribute("paginationInfo", paginationInfo);
model.addAttribute("pageNo", currentPageNo);
return "board"; // jsp file name
}
와 진짜 길어 . 못할듯~
'2023.11.21-2024.05.31' 카테고리의 다른 글
20240221 스프링(글쓰기, 댓글쓰기 ip, 엔터키처리) (1) | 2024.02.21 |
---|---|
240220 스프링(로그인, 로그아웃) (0) | 2024.02.20 |
20240219 스프링(웹표준 기술 - 모달 풋터,상세보기 모달,swal, 댓글창 만들기, 댓글 출력하기) (0) | 2024.02.19 |
20240216 스프링4일차(util, error,modal) (0) | 2024.02.16 |
20230215 스프링3일차() (0) | 2024.02.15 |