Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- EnhancedFor
- 어윈 사용법
- 오라클
- oracle
- 한국건설관리시스템
- 생성자오버로드
- NestedFor
- 객체 비교
- 자동차수리시스템
- 자바
- 제네릭
- abstract
- 컬렉션 타입
- exception
- 환경설정
- 예외미루기
- 사용자예외클래스생성
- 정수형타입
- 참조형변수
- 대덕인재개발원
- Java
- 집합_SET
- 메소드오버로딩
- 추상메서드
- GRANT VIEW
- 예외처리
- cursor문
- 다형성
- 컬렉션프레임워크
- 인터페이스
Archives
- Today
- Total
거니의 velog
231216_SPRING CRUD 보강 5 본문
package kr.or.ddit.controller.board;
import java.util.List;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import kr.or.ddit.service.IBoardService;
import kr.or.ddit.vo.BoardVO;
import kr.or.ddit.vo.PaginationInfoVO;
@Controller
@RequestMapping("/board")
public class BoardController {
@Inject
private IBoardService boardService;
@RequestMapping(value="/list.do", method = RequestMethod.GET)
public String boardList(
@RequestParam(name = "page", required = false, defaultValue = "1") int currentPage,
@RequestParam(required = false, defaultValue = "title") String searchType,
@RequestParam(required = false) String searchWord,
Model model
) {
PaginationInfoVO<BoardVO> pagingVO = new PaginationInfoVO<BoardVO>();
// 검색을 진행
if(StringUtils.isNotBlank(searchWord)) {
pagingVO.setSearchType(searchType);
pagingVO.setSearchWord(searchWord);
model.addAttribute("searchType", searchType);
model.addAttribute("searchWord", searchWord);
}
pagingVO.setCurrentPage(currentPage); // startRow, endRow, startPage, endPage 가 결정
int totalRecord = boardService.selectBoardCount(pagingVO); // totalRecord(총 게시글 수)
pagingVO.setTotalRecord(totalRecord); // totalPage 결정
List<BoardVO> dataList = boardService.selectBoardList(pagingVO);
pagingVO.setDataList(dataList);
model.addAttribute("pagingVO", pagingVO);
return "board/list";
}
@RequestMapping(value="/detail.do", method = RequestMethod.GET)
public String boardDetail(int boNo, Model model) {
BoardVO boardVO = boardService.selectBoard(boNo);
model.addAttribute("board", boardVO);
return "board/detail";
}
@RequestMapping(value="/form.do", method = RequestMethod.GET)
public String boardForm() {
return "board/form";
}
}
package kr.or.ddit.service;
import java.util.List;
import kr.or.ddit.vo.BoardVO;
import kr.or.ddit.vo.PaginationInfoVO;
public interface IBoardService {
public int selectBoardCount(PaginationInfoVO<BoardVO> pagingVO);
public List<BoardVO> selectBoardList(PaginationInfoVO<BoardVO> pagingVO);
public BoardVO selectBoard(int boNo);
}
package kr.or.ddit.service.impl;
import java.util.List;
import javax.inject.Inject;
import org.springframework.stereotype.Service;
import kr.or.ddit.mapper.IBoardMapper;
import kr.or.ddit.service.IBoardService;
import kr.or.ddit.vo.BoardVO;
import kr.or.ddit.vo.PaginationInfoVO;
@Service
public class BoardServiceImpl implements IBoardService {
@Inject
private IBoardMapper boardMapper;
@Override
public int selectBoardCount(PaginationInfoVO<BoardVO> pagingVO) {
return boardMapper.selectBoardCount(pagingVO);
}
@Override
public List<BoardVO> selectBoardList(PaginationInfoVO<BoardVO> pagingVO) {
return boardMapper.selectBoardList(pagingVO);
}
@Override
public BoardVO selectBoard(int boNo) {
boardMapper.incrementhit(boNo); // 조회수 증가
return boardMapper.selectBoard(boNo);
}
}
package kr.or.ddit.mapper;
import java.util.List;
import kr.or.ddit.vo.BoardVO;
import kr.or.ddit.vo.PaginationInfoVO;
public interface IBoardMapper {
public int selectBoardCount(PaginationInfoVO<BoardVO> pagingVO);
public List<BoardVO> selectBoardList(PaginationInfoVO<BoardVO> pagingVO);
public void incrementhit(int boNo);
public BoardVO selectBoard(int boNo);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.or.ddit.mapper.IBoardMapper">
<sql id="boardSearch">
<if test="searchType != null and searchType == 'title'">
and (bo_title like '%' || #{searchWord} || '%')
</if>
<if test="searchType != null and searchType == 'writer'">
and (bo_writer like '%' || #{searchWord} || '%')
</if>
<if test="searchType != null and searchType == 'both'">
and (bo_title like '%' || #{searchWord} || '%')
and (bo_writer like '%' || #{searchWord} || '%')
</if>
</sql>
<select id="selectBoardCount" parameterType="pagingVO" resultType="int">
select count(bo_no)
from board
where 1=1
<include refid="boardSearch" />
</select>
<select id="selectBoardList" parameterType="pagingVO" resultType="boardVO">
select
b.*
from (
select
a.*, row_number() over (order by a.bo_no desc) rnum
from (
select
bo_no, bo_title, bo_content, bo_writer, bo_date, bo_hit
from board
where 1=1
<include refid="boardSearch" />
order by bo_no desc
) a
) b
<![CDATA[
where b.rnum >= #{startRow} and b.rnum <= #{endRow}
]]>
</select>
<update id="incrementhit" parameterType="int">
update board
set
bo_hit = bo_hit + 1
where bo_no = ${boNo}
</update>
<select id="selectBoard" parameterType="int" resultType="boardVO">
select
bo_no, bo_title, bo_content, bo_writer, bo_date, bo_hit
from board
where bo_no = ${boNo}
</select>
</mapper>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<div class="container-fluid px-2 px-md-4">
<div class="page-header min-height-300 border-radius-xl mt-4"
style="background-image: url('https://images.unsplash.com/photo-1531512073830-ba890ca4eba2?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1920&q=80');">
<span class="mask bg-gradient-secondary opacity-6"></span>
</div>
<div class="card card-body mx-3 mx-md-4 mt-n6">
<div class="row gx-4 mb-2">
<div class="col-md-8">
<div class="h-100">
<h5 class="mb-1">${board.boTitle }</h5>
</div>
</div>
</div>
<ul class="list-group">
<li
class="list-group-item border-0 d-flex align-items-center px-0 mb-2 pt-0">
<div class="avatar me-3">
<img src="${pageContext.request.contextPath }/resources/assets/img/kal-visuals-square.jpg" alt="kal"
class="border-radius-lg shadow">
</div>
<div
class="d-flex align-items-start flex-column justify-content-center">
<h6 class="mb-0 text-sm">${board.boDate } / ${board.boHit }</h6>
<p class="mb-0 text-xs">${board.boWriter }</p>
</div>
</li>
</ul>
<div class="row">
<div class="col-md-12">
<div class="card card-plain h-100">
<div class="card-header pb-0 p-3">
<h6 class="mb-0">내용</h6>
</div>
<div class="card-body p-3">${board.boContent }</div>
<hr />
<div class="col-md-12">
<div class="row">
<div class="col-md-2">
<div class="card shadow-lg">
<div
class="card-header mt-n4 mx-3 p-0 bg-transparent position-relative z-index-2">
<a class="d-block blur-shadow-image text-center">
<img src="${pageContext.request.contextPath}/resources/assets/img/icons/img.jpg" alt="img-blur-shadow" class="img-fluid shadow border-radius-lg">
</a>
<div class="colored-shadow" style="background-image: url("https://images.unsplash.com/photo-1536321115970-5dfa13356211?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80");"></div>
</div>
<div class="card-body text-center bg-white border-radius-lg p-3 pt-0">
<h6 class="mt-3 mb-1 d-md-block d-none">
파일명을 입력하세요!
</h6>
<p class="mb-0 text-xs font-weight-bolder text-info text-uppercase">
<button type="button" class="btn btn-primary btn-sm fileDelete">
delete
</button>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="card-footer p-3">
<button type="button" class="btn btn-outline-primary" id="delBtn">삭제</button>
<button type="button" class="btn btn-outline-secondary" id="udtBtn">수정</button>
<button type="button" class="btn btn-outline-success" onclick="javascript:location.href='/board/list.do'">목록</button>
</div>
</div>
</div>
</div>
</div>
</div>
- http://localhost/board/detail.do?boNo=13
'대덕인재개발원_웹기반 애플리케이션' 카테고리의 다른 글
231216_SPRING CRUD 보강 7 (0) | 2023.12.16 |
---|---|
231216_SPRING CRUD 보강 6 (0) | 2023.12.16 |
231216_SPRING CRUD 보강 4 (0) | 2023.12.16 |
231216_SPRING CRUD 보강 3 (0) | 2023.12.16 |
231216_SPRING CRUD 보강 2 (0) | 2023.12.15 |