[Spring] 09. 게시판 글쓰기개발자가 되기까지 (2023.08.16~2024.04.15)/[Spring] Basic Web2024. 1. 16. 23:15
Table of Contents
src > main > webapp > WEB-INF > views > board에 register.jsp를 생성한다.
register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:include page="../layout/header.jsp"></jsp:include>
<jsp:include page="../layout/nav.jsp"></jsp:include>
<h2>글쓰기</h2>
<hr>
<div class="container-md">
<form action="/board/register" method="post">
<div class="mb-3">
<label for="title" class="form-label">제목</label>
<input
type="text" name="title" class="form-control" id="title">
</div>
<div class="mb-3">
<label for="writer" class="form-label">작성자</label>
<input
type="text" name="writer" class="form-control" id="writer">
</div>
<div class="mb-3">
<label for="content" class="form-label">내용</label>
<textarea name="content" class="form-control" id="content" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">등록</button>
<a href="/"><button type="button" class="btn btn-danger">취소</button></a>
</form>
</div>
<jsp:include page="../layout/footer.jsp"></jsp:include>
BoardController.java
package com.basicWeb.www.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.basicWeb.www.domain.BoardVO;
import com.basicWeb.www.service.BoardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequestMapping("/board/*")
@RequiredArgsConstructor
@Controller
public class BoardController {
private final BoardService bsv;
@GetMapping("/register")
public void register() {}
@PostMapping("/register")
public String register(BoardVO bvo) {
bsv.register(bvo);
return "index";
}
}
BoardService.interface
package com.basicWeb.www.service;
import com.basicWeb.www.domain.BoardVO;
public interface BoardService {
void register(BoardVO bvo);
}
BoardServiceImpl.java
package com.basicWeb.www.service;
import org.springframework.stereotype.Service;
import com.basicWeb.www.domain.BoardVO;
import com.basicWeb.www.repository.BoardDAO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor
@Service
public class BoardServiceImpl implements BoardService{
private final BoardDAO bdao;
@Override
public void register(BoardVO bvo) {
// TODO Auto-generated method stub
bdao.register(bvo);
}
}
BoardDAO.interface
package com.basicWeb.www.repository;
import com.basicWeb.www.domain.BoardVO;
public interface BoardDAO {
void register(BoardVO bvo);
}
boardMapper.xml
<?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="com.basicWeb.www.repository.BoardDAO">
<insert id="register">
insert into board (title, writer, content)
values (#{title}, #{writer}, #{content})
</insert>
</mapper>
<글쓰기 화면>
[Spring] 09. 게시판 글쓰기
(다음 게시물 예고편)
[Spring] 10. 게시판 리스트
728x90
@rlozlr :: 얼렁뚱땅 개발자
얼렁뚱땅 주니어 개발자
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!