Application.java
java
1package com.example; 2 3 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6import org.springframework.context.annotation.ComponentScan; 7 8@ComponentScan 9@EnableAutoConfiguration 10public class Application { 11 public static void main(String[] args) { 12 SpringApplication.run(Application.class, args); 13 } 14} 15 16```CustomerController.java 17
package com.example.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@EnableAutoConfiguration
public class CustomerController {
@RequestMapping("/hello") public String hello(@RequestParam(value="name", required=false, defaultValue="masa") String name, Model model) { model.addAttribute("name", name); return "hello"; } public static void main(String[] args) { SpringApplication.run(CustomerController.class, args); }
pom.xml ```xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>hajiboot-thymeleaf2</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name></name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.lazyluke</groupId> <artifactId>log4jdbc-remix</artifactId> <version>0.2.7</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
html
1<!DOCTYPE HTML> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4 <title>Thymeleaf で出力しますよ</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6</head> 7<body> 8 <p th:text="'こんにちは, ' + ${name} + 'さん!'" /> 9</body> 10</html>
で実行して
http://localhost:8080/hello
にいくとこうなってしまいます
どうすれば画面が表示されるようになるのでしょうか??
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。