Q&A
前提・実現したいこと
Spring BootとThymeleafの勉強中なのですが、
IndexページからTestページへの画面移動が出来ません。
発生している問題・エラーメッセージ
HTTP404 Webページが見つかりません
該当のソースコード
フォルダ構成
src-main┬java-sample┬controller┬Index.java | | └Test.java | └Application.java └resources┬config-application.yml └templates┬index.html └test.html
java
1package sample.controller; 2 3import org.springframework.stereotype.Controller; 4import org.springframework.web.bind.annotation.RequestMapping; 5 6@Controller 7public class Index { 8 9 @RequestMapping("/") 10 public String index() { 11 System.out.println("OK"); 12 return "index"; 13 } 14}
java
1package sample.controller; 2 3import org.springframework.stereotype.Controller; 4import org.springframework.web.bind.annotation.RequestMapping; 5import org.springframework.web.servlet.ModelAndView; 6 7@Controller 8public class Test { 9 10 @RequestMapping("/test") 11 public ModelAndView getCharacter(ModelAndView mav) { 12 System.out.println("OK"); 13 mav.setViewName("test"); 14 System.out.println("OK2"); 15 return mav; 16 } 17}
html
1<!DOCTYPE html> 2<html lang="ja" xmlns:th="http://www.thymeleaf.org"> 3<head> 4<meta charset="UTF-8"> 5<meta name="author" content="tallwide"> 6<title>test</title> 7</head> 8<body> 9 <a href="test.html" th:href="@{'test.html'}">リンク</a> 10</body> 11</html>
html
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<meta charset="UTF-8"> 5<title>Insert title here</title> 6</head> 7<body> 8<h1>Test</h1> 9</body> 10</html>
yaml
1spring: 2 thymeleaf: 3 mode: HTML
gradle
1buildscript { 2 ext { 3 springBootVersion = '2.1.0.RELEASE' 4 } 5 repositories { 6 mavenCentral() 7 } 8 dependencies { 9 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 } 11} 12 13apply plugin: 'java' 14apply plugin: 'eclipse' 15apply plugin: 'org.springframework.boot' 16apply plugin: 'io.spring.dependency-management' 17 18group = 'com.test' 19version = '0.0.1-SNAPSHOT' 20 21// Javaバージョン 22def jdkVersion = 1.8 23sourceCompatibility = jdkVersion 24targetCompatibility = jdkVersion 25 26repositories { 27 mavenCentral() 28} 29 30 31dependencies { 32 33 implementation('org.springframework.boot:spring-boot-devtools') 34 implementation('org.springframework.boot:spring-boot-starter-web') 35 implementation('org.springframework.boot:spring-boot-starter-thymeleaf') 36 testImplementation('org.springframework.boot:spring-boot-starter-test') 37}
試したこと
・コンソール出力を処理の途中に挿し込んでみたところ、リンク先に対応したコントローラが動作していないことが判明しました。(Test.javaのコンソール出力処理がまったく行われない)
・SpringBootやThymeleafの入門サイトを多数確認し、リンクや@RequestMappingの引数を何度も書き直してみましたが、いずれの方法でも症状は改善しませんでした。
補足情報(FW/ツールのバージョンなど)
eclipse photon
gradle 4.10.2
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2018/11/03 09:20