3
1

More than 1 year has passed since last update.

【SpringBoot】で簡単なアプリを作ってみよう!(2/3) ~画面表示~

Last updated at Posted at 2021-03-29

この記事は以下の続きです。
SpringBoot2で簡単なアプリを作ってみよう!(1/3) ~環境設定~

第2回目は画面表示をしていきます!

画面を表示する

パスについてですが、前回も載せておりますが戻って確認するのも面倒だと思うのでこちらにも載せておきます。
スクリーンショット 2021-03-27 22.25.27.png

HTMLを作成する

"xmlns"で名前空間を宣言することによりThymeleafタグを使用することができるようになります。
(<th:xxx>)←こんな感じのタグを使います。

productManage.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<title>商品管理</title>
</head>
<body>
	<p>商品管理</p>
	<table>
		<tr>
			<th>商品名</th>
			<th>商品数</th>
		</tr>
	</table>
</body>
</html>

コントローラを作成する

次にコントローラのパッケージ、ファイルを作成します。
@ControllerをつけることによってDIコンテナに登録することができます。
(DIについてはまた別の記事を書こうと思ってます。)
@GetMappingでGETリクエストを受け取りHTMLを返しています。

AdminController.java
@Controller
public class AdminController {

	@GetMapping("/")
	public String index(Model model) {
		return "productManage";
	}
}

ここまできたら画面を確認してみましょう。

下記URLで画面が表示されるはずです。
http://localhost:8080/

◇画面イメージ

スクリーンショット 2021-03-28 13.04.08.png

↓第3回はこちら
SpringBoot2で簡単なアプリを作ってみよう!(3/3) ~DB操作~

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1