Skip to content
Permalink
Browse files

lecture05

  • Loading branch information...
teachingprogramming committed May 15, 2018
1 parent 7c1bbd1 commit afe1a7520cad579c4247c6d957b0951a70e84567
@@ -1,6 +1,6 @@
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
@@ -1,6 +1,6 @@
#Tue Feb 06 12:27:20 CET 2018
#Tue May 15 12:17:25 JST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip
@@ -0,0 +1,52 @@
package d00000.webapp;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/lect05")
public class Lect05Controller {
public Map<String, String> dictionary;

public Lect05Controller() {
dictionary = new HashMap<String, String>();
}

@RequestMapping("register_form")
public String registerForm() {
return "lect05/register_form";
}

@RequestMapping("register_result")
public String registerResult(@RequestParam("english") String english, @RequestParam("japanese") String japanese) {
dictionary.put(english, japanese);
return "lect05/register_result";
}

@RequestMapping("search_form")
public String searchForm() {
return "lect05/search_form";
}

@RequestMapping("search_result")
public String searchResult(@RequestParam("english") String english, ModelMap modelMap) {
String japanese = dictionary.get(english); // ない場合はnullが入る
modelMap.addAttribute("english", english);
modelMap.addAttribute("japanese", japanese);
return "lect05/search_result";
}

@RequestMapping("list")
public String list(ModelMap modelMap) {
modelMap.addAttribute("dictionary", dictionary);
return "lect05/list";
}



}
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
</head>
<body>

<nav th:fragment="menu">
<ul>
<li><a href="/lect05/register_form">登録</a></li>
<li><a href="/lect05/search_form">検索</a></li>
<li><a href="/lect05/list">一覧</a></li>
</ul>
</nav>

</body>
</html>
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
<style>
table {
border-collapse: collapse;
}
th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>辞書: 一覧</h1>

<table>
<tr>
<th>英語</th>
<th>日本語</th>
</tr>
<tr th:each="english:${dictionary.keySet()}">
<td th:text="${english}">english</td>
<td th:text="${dictionary.get(english)}">japanese</td>
</tr>
</table>

<hr/>
<nav th:include="lect05/common::menu"></nav>
</body>
</html>
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
</head>
<body>
<h1>辞書: 登録</h1>

<form action="/lect05/register_result" method="post">
<label>
英語: <input type="text" name="english" width="300">
</label><br/>
<label>
日本語: <input type="text" name="japanese" width="300">
</label><br/>
<input type="submit"/>
</form>

<hr/>
<nav th:include="lect05/common::menu"></nav>
</body>
</html>
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
</head>
<body>
<h1>辞書: 登録</h1>

<p>
登録しました
</p>

<hr/>
<nav th:include="lect05/common::menu"></nav>
</body>
</html>
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
</head>
<body>
<h1>辞書: 検索</h1>

<form action="/lect05/search_result" method="post">
<label>
英語: <input type="text" name="english" width="300">
</label><br/>
<input type="submit"/>
</form>

<hr/>
<nav th:include="lect05/common::menu"></nav>
</body>
</html>
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>辞書</title>
</head>
<body>
<h1>辞書: 検索</h1>

<p th:if="${japanese != null}">
「<span th:text="${english}">english</span>」の日本語は「<span th:text="${japanese}">japanese</span>」です。
</p>
<p th:if="${japanese == null}">
「<span th:text="${english}">english</span>」の日本語は登録されていません。
</p>

<hr/>
<nav th:include="lect05/common::menu"></nav>
</body>
</html>

0 comments on commit afe1a75

Please sign in to comment.
You can’t perform that action at this time.