java
1@Controller 2public class HelloController { 3 4 @GetMapping("/hello") 5 public String getHello(){ 6 return "hello"; 7 } 8 9 @PostMapping("/Hello") 10 public String postRequest(@RequestParam("text1")String str, Model model){ 11 12 model.addAttribute("Sample", str); 13 14 return "helloResponse"; 15 } 16}
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3 4<head> 5 <meta charset="UTF-8"> 6 <title>Hello World</title> 7</head> 8<body> 9 <h1>Hello World</h1> 10 <form method="post" action="/hello"> 11 好きな文字を入力: 12 <input type="text" name="text1" th:value="${text1_value}"/> 13 <input type="submit" value="クリック" /> 14 </form> 15</body> 16</html>
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4 <meta charset="UTF-8"> 5</head> 6<body> 7 <h1>HelloResponse</h1> 8 <p th:text="${sample}"></p> 9</body> 10
pom.xml
1<?xml version="1.0" encoding="UTF-8"?> 2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.5.2</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.example</groupId> 12 <artifactId>SpringSample</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>SpringSample</name> 15 <description>Demo project for Spring Boot</description> 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 19 <java.version>1.8</java.version> 20 <thymeleaf.version>3.0.12.RELEASE</thymeleaf.version> 21 <thymeleaf-layout-dialect.version>2.1.2</thymeleaf-layout-dialect.version> 22 <thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version> 23 </properties> 24 <dependencies> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-data-jdbc</artifactId> 28 </dependency> 29 <dependency> 30 <groupId>org.springframework.boot</groupId> 31 <artifactId>spring-boot-starter-thymeleaf</artifactId> 32 </dependency> 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-web</artifactId> 36 </dependency> 37 38 <dependency> 39 <groupId>org.springframework.boot</groupId> 40 <artifactId>spring-boot-devtools</artifactId> 41 <scope>runtime</scope> 42 <optional>true</optional> 43 </dependency> 44 <dependency> 45 <groupId>com.h2database</groupId> 46 <artifactId>h2</artifactId> 47 <scope>runtime</scope> 48 </dependency> 49 <dependency> 50 <groupId>org.projectlombok</groupId> 51 <artifactId>lombok</artifactId> 52 <optional>true</optional> 53 </dependency> 54 <dependency> 55 <groupId>org.springframework.boot</groupId> 56 <artifactId>spring-boot-starter-test</artifactId> 57 <scope>test</scope> 58 </dependency> 59 </dependencies> 60 61 <build> 62 <plugins> 63 <plugin> 64 <groupId>org.springframework.boot</groupId> 65 <artifactId>spring-boot-maven-plugin</artifactId> 66 <configuration> 67 <excludes> 68 <exclude> 69 <groupId>org.projectlombok</groupId> 70 <artifactId>lombok</artifactId> 71 </exclude> 72 </excludes> 73 </configuration> 74 </plugin> 75 </plugins> 76 </build> 77 78</project> 79
SpringBootの初学者です。
単純に画面から画面に、入力した値を渡すだけのサンプルを作成したかったのですが、
Thymeleafの値の箇所にこのようなエラーが出てしまいます。
・'text1_value' を解決できません
・'sample' を解決できません
かなり初歩的な質問で申し訳ございませんが、よろしくお願いします。