Web Application
Web Application
Web Application
オブジェクト間(投稿コントローラ、スタッフ、DAO)の割り当てと実行方法
Presentation
DataService(出版物DAO)
Table
メンバー登録ビジネス
Usease UMLの描画
MVC(Model View Control)
画像コード
MVCの基本構造のプレゼンテーションと実践
例(投稿の準備)
package com.stone.springmvc.board.presentation;
import java.util.ArrayList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import com.stone.springmvc.board.common.Board;
import com.stone.springmvc.board.service.게시물업무자;
@Controller
public class Board컨트롤러 {
게시물업무자 한게시물업무자=new 게시물업무자();
@GetMapping("/prepareboard")
public ModelAndView 게시물입력을준비하다() {
ModelAndView mv = new ModelAndView();
mv.setViewName("게시물등록창");
// 뷰 이름 등록
// mv.addObject(attributeValue) // 보내는 데이터가 있으면 사용
return mv;
}
}
例(投稿リストの表示)
マッピングを指定して
package com.stone.springmvc.board.presentation;
import java.util.ArrayList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import com.stone.springmvc.board.common.Board;
import com.stone.springmvc.board.service.게시물업무자;
@Controller
public class Board컨트롤러 {
@GetMapping("/listboard")
public ModelAndView 게시물목록을출력하다() {
ArrayList<Board> 모든게시물들 = 한게시물업무자.모두수집하다();
// 모든게시물들 수집(업무처리)
ModelAndView mv = new ModelAndView();
mv.setViewName("게시물목록창");
// 게시물목록창.jsp
mv.addObject("listboard", 모든게시물들);
// 게시물목록창.jsp에 모든게시물들을 listboard라는 이름으로 Mapping
return mv;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.stone.springmvc.board.common.Board" %>
<% ArrayList<Board> boards= (ArrayList<Board>) request.getAttribute("listboard"); %>
<!-- 컨트롤러에서 Mapping한 listboard를 board로 저장 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 게시물목록출력 -->
<h1>게시물 목록</h1>
<ul>
<% for(int 일련번호=0;일련번호<boards.size();일련번호++){
Board 게시물 =boards.get(일련번호);//zero base
%>
<li><%=일련번호+1 %>
<a href="/board/<%= 게시물.getNo() %>"><%= 게시물.getTitle() %></a>
</li>
<%} %>
</ul>
<br><button onclick="location.href='/main'">메인</button>
</body>
</html>
マッピングを指定して
package com.stone.springmvc.board.presentation;
import java.util.ArrayList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.stone.springmvc.board.common.Board;
import com.stone.springmvc.board.service.게시물업무자;
@Controller
public class Board컨트롤러 {
@GetMapping("/viewboard")
public ModelAndView 상세게시물을조회하다(@RequestParam("no") int 게시물번호) {
// @RequestParamint(" ") : 파라미터가 넘어올때 " "안의 이름으로 맞추겠다라는 뜻?
// 업무-게시물찾기
Board 특정게시물 = 한게시물업무자.찾다By번호(게시물번호);
ModelAndView mv = new ModelAndView();
mv.setViewName("게시물상세창");
// board에 게시물상세창.jsp 생성
mv.addObject("board", 특정게시물);
// 여기 Controller에서 특정게시물 객체를 게시물상세창.jsp에서 사용하기 위해 board로 Mapping
return mv;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.stone.springmvc.board.common.*" %>
<% Board board= (Board) request.getAttribute("board"); %>
<!-- controller에서 mapping된 board를 여기서 사용할 수 있도록 board로 지정 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>게시물 상세</h1>
제목<%=board.getTitle()%> <br>
내용<textarea cols="25" rows="5" name="contents" readonly><%= board.getContents()%></textarea><br>
<button onclick="location.href='/boards'">목록</button>
<button onclick="location.href='/main'">메인</button>
<!-- board로 저장된 값의 제목, 내용을 출력 -->
</body>
</html>
Reference
この問題について(Web Application), 我々は、より多くの情報をここで見つけました https://velog.io/@sig6774/Web-Applicationテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol