質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

1回答

1258閲覧

SpringBoot Thymeleaf 値のエラー

退会済みユーザー

退会済みユーザー

総合スコア0

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2021/06/26 07:07

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' を解決できません

かなり初歩的な質問で申し訳ございませんが、よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2021/06/26 07:36

退会してしまったら解決にならないのに
guest

回答1

0

addAttributeしてるのはSample
sampleでもtext1_valueでもありません。

全角半角はもちろん、大文字小文字も別扱いです。

投稿2021/06/26 07:56

m.ts10806

総合スコア80850

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問