Spring]Spring環境とView設定
スプリングとは
SpringフレームワークはJavaプラットフォーム向けのオープンソースアプリケーションフレームワークであり、簡単にSpringと呼ぶ.主にダイナミックWebサイトの開発に多くのサービスを提供しています.
開発環境構築準備
プロジェクトの作成
https://start.spring.io/
->本来spring開発者は開発環境に次々と面倒をかける必要がありますが、springガイドを使用することで開発環境を個別に設定する必要はありません
次の設定を選択し、必要な残りの部分を選択します.
Java 11
Dependencies -> Spring Web, Thymeleaf
運転確認
src/java/自分で設定したartifactid/hellospringApplication->run
こうして浮かび上がれば成功する
ビューの設定
Whitelabel Error Pageではなく別の画面に設定するにはresource/indexを使用します.htmlファイルを生成します.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
Hello Spring
<a href = "/spring">go localhost:8080/spring</a> <!-- localhost:8080/spring으로 이동-->
</body>
</html>
localhost:8080/hello、helloに移動します.受信htmlのコントローラを作成します.Controller.java
package hello.hellospring.controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@org.springframework.stereotype.Controller
public class Controller {
@GetMapping("spring") // localhost:8080/spring을 받으면 아래 메서드 실행
public String hello(Model model){
model.addAttribute("key", "spring!!"); // key = data, value = hello!!
return "hello"; // hello.html로 이동
}
}
hello.html<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello. ' + ${key}" ></p>
</body>
</html>
実行画面
Reference
この問題について(Spring]Spring環境とView設定), 我々は、より多くの情報をここで見つけました https://velog.io/@nyong_i/Spring-Spring-환경-및-View-설정テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol