지금, 역 B 형 springcloud에서 알아보기 비디오에 나타나는 작은 오류의 요약 제거를 요약, 오류가 발생하기 쉬운 장소의 일부를 생각 나게했다
: 아웃 바운드 링크 b를 https://www.bilibili.com/video/av55993157
데이터 링크 :
https://pan.baidu.com/s/1o0Aju3IydKA15Vo1pP4z5w
추출 코드 : 21ru
링크
섹션의 링크를 다음 :
다음 목록 요약
새로운 건설 → 부모 치어 → 자원 / 애플리케이션과 자바 → COM / 사우스 윈드 / 컨트롤러 / HelloHandler → 시작 클래스 응용 프로그램
복사 개체 / 학생 및 수정이 HelloHandler가 → 저장소 → 삭제 웹 애플리케이션은 / index.jsp를의 index.jsp → 다시 시작 응용 프로그램 내에서 새로운 코드를 추가
index.jsp를 추가 코드 컨트롤러를 추가 → / HelloHandler는 응용 프로그램 코드를 다시 시작 →
새로운 코드 update.jsp save.jsp 및 웹 애플리케이션은 → 제어기 / HelloHandler → 검출 코드 추가인가
구현 세부 사항 :
1. 새 프로젝트 springjsp의 작성
틱은 선택 웹 애플리케이션은 다음
뒤에 다음이었다, 그리고 마지막으로 마침
먼저해야 만들 경우 다운로드에 대한 대기, 오래 기다릴!
반 시간 후에 업데이트는 바닥 마무리가 완료됩니다
2. 부모 치어는
부분 종속 속성 후 추가 코드를 삭제 :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jsp-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--JSTL-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
첫 번째는 해결 될 수없는 빨간색이있을 수 있습니다, 위의 코드를 가입
하면 식별 할 수있는 적색 부분처럼 새로 고침을 기다리는
부모 POM 파일을 전체 코드를 :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.southwind</groupId>
<artifactId>springjsp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>springjsp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jsp-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--JSTL-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
<build>
<finalName>springjsp</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
새 폴더의 주요 패킷 자원 3.
및 번들 리소스를 표시 할
새 폴더 자바 넥타이, 마크
application.yml에서 파일 리소스에 새 구성 파일을
채우기 코드 :
server:
port: 8181
spring: #视图解析器
mvc:
view:
prefix: / #前缀
suffix: .jsp #后缀
4. 자바 com.southwind.controller의 패키지 레코드 폴더
컨트롤러의 새로운 클래스 HelloHandler.java 제어 패킷
태그 :
package com.southwind.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
/*
@Controller 可以解析return 的 jsp和 html 页面
@RestController就不能 ,但 @RestController = @ResponseBody + @Controller
* */
@RequestMapping("/hello")
public class HelloHandler {
@GetMapping("/index")
public String index(){
System.out.println("index...");
return "index";
}
}
응용 프로그램의 시작 클래스의 새 패키지를 만들기 5. 사우스 윈드
태그를 :
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
6. 시작 응용 프로그램
입력에 http : // localhost를 : 8181 / 인사 / 색인
이 안녕하세요 세계에서 :
인덱스 ... 콘솔에서 인쇄
7. 기업 및 프로젝트의 저장소 사본 패킷에 패킷이 패키지 사우스 윈드하는
HelloHandler 8. 내용 :
코드가된다 :
package com.southwind.controller;
import com.southwind.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
/*
@Controller 可以解析return 的 jsp和 html 页面
@RestController就不能 ,但 @RestController = @ResponseBody + @Controller
* */
@RequestMapping("/hello")
public class HelloHandler {
@Autowired
private StudentRepository studentRepository;
@GetMapping("/index")
public ModelAndView index(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
modelAndView.addObject("list",studentRepository.findAll());
return modelAndView;
}
}
9. index.jsp를 웹 애플리케이션 삭제의 패키지
인덱스라는 이름의 새 JSP 파일
9.1
, 8 호선 <% @ 페이지의 contentType = " text / html과; 문자셋 = UTF-8"언어 = "자바"%> 나중에 추가 :
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
9.2의 코드를 <BODY> </ 몸> 추가 :
<h1>学生信息</h1>
<table>
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生年龄</th>
</tr>
<c:forEach items="${list}" var="student">
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.age}</td>
</tr>
</c:forEach>
</table>
그래서 index.jsp를 전체 코드 :
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020-03-05
Time: 12:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>学生信息</h1>
<table>
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生年龄</th>
</tr>
<c:forEach items="${list}" var="student">
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.age}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
10. 다시 시작 클래스 응용 프로그램
// localhost를 : 8181 / 헬로 / 인덱스 HTTP 입력
(11) 수정, 삭제 작업이 완료 보완 :
11.1의 index.jsp에
<th>学生编号</th>
<th>学生姓名</th>
<th>学生年龄</th>
<th>操作</th>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.age}</td>
<td>
<a href="/hello/findById/${student.id}">修改</a>
<a href="/hello/deleteById/${student.id}">删除</a>
</td>
의 <표> </ 테이블>에서 (뒷면에주의!) 나중에 추가 된 /
저장 슬래시 테이크 루트 디렉토리 앞의 시작을 나타냅니다
<a href="/save.jsp">添加学生</a>
코드를 index.jsp를 완료합니다 :
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020-03-05
Time: 12:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>学生信息</h1>
<table>
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生年龄</th>
<th>操作</th>
</tr>
<c:forEach items="${list}" var="student">
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.age}</td>
<td>
<a href="/hello/findById/${student.id}">修改</a>
<a href="/hello/deleteById/${student.id}">删除</a>
</td>
</tr>
</c:forEach>
</table>
<a href="/save.jsp">添加学生</a>
</body>
</html>
11.2 컨트롤러에 코드를 추가 / HelloHandler 지역 :
참고 @GetMapping 날의 일부가 잘못하지 않았다 삭제!
@GetMapping("/deleteById/{id}")
public String deleteById(@PathVariable("id")long id){
studentRepository.deleteById(id);
return "redirect:/hello/index";/* redirect:重对象 */
}
테스트 : 다시 시작 응용 프로그램
// localhost를 : 8181 / 안녕하세요 HTTP 입력 / 인덱스
삭제를 클릭 :
웹 애플리케이션의 11.3 save.jsp 새 폴더
<BODY> </ BODY>의 코드를 추가하는 :
<form action="/hello/save" method="post">
ID:<input type="text" name ="id"/><br/>
name:<input type="text" name ="name"/><br/>
age:<input type="text" name ="age"/><br/>
<input type="submit" value="提交"/>
</form>
update.jsp의 11.4 웹 애플리케이션 새 폴더
의 추가 코드를 <BODY> </ BODY> :
<form action="/hello/update" method="post">
ID:<input type="text" name ="id" value="${student.id}" readonly/><br/>
name:<input type="text" name ="name" value="${student.name}"/><br/>
age:<input type="text" name ="age" value="${student.age}"/><br/>
<input type="submit" value="提交"/>
11.5 컨트롤러에 코드를 추가 / HelloHandler 지역 :
하는 업데이트를 해당 @PostMapping ( "/ 업데이트") 내가 잘못했다
modelAndView.setViewName ( "업데이트"); / * 이 업데이트의 웹 애플리케이션 / update.jsp로 이동하는 것입니다 * /
@PostMapping("/save")
public String save(Student student){
studentRepository.saveorupdate(student);
return "redirect:/hello/index";
}
@PostMapping("/update")
public String update(Student student){
studentRepository.saveorupdate(student);
return "redirect:/hello/index";
}
@GetMapping("/findById/{id}")
public ModelAndView findById(@PathVariable("id")long id){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("update");/*这个update就是跳转至webapp/update.jsp中*/
modelAndView.addObject("student",studentRepository.findById(id));
return modelAndView;
}
12 체크
// localhost를 : 8181 / 헬로 / 인덱스의 HTTP로
12.1 클릭 추가 학생
제출 :
12.2이 정보를 수정
나이를 수정, 제출 된
12.3 삭제