前提・実現したいこと
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
package sample.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Index { @RequestMapping("/") public String index() { System.out.println("OK"); return "index"; } }
java
package sample.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class Test { @RequestMapping("/test") public ModelAndView getCharacter(ModelAndView mav) { System.out.println("OK"); mav.setViewName("test"); System.out.println("OK2"); return mav; } }
html
<!DOCTYPE html> <html lang="ja" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <meta name="author" content="tallwide"> <title>test</title> </head> <body> <a href="test.html" th:href="@{'test.html'}">リンク</a> </body> </html>
html
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h1>Test</h1> </body> </html>
yaml
spring: thymeleaf: mode: HTML
gradle
buildscript { ext { springBootVersion = '2.1.0.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.test' version = '0.0.1-SNAPSHOT' // Javaバージョン def jdkVersion = 1.8 sourceCompatibility = jdkVersion targetCompatibility = jdkVersion repositories { mavenCentral() } dependencies { implementation('org.springframework.boot:spring-boot-devtools') implementation('org.springframework.boot:spring-boot-starter-web') implementation('org.springframework.boot:spring-boot-starter-thymeleaf') testImplementation('org.springframework.boot:spring-boot-starter-test') }
試したこと
・コンソール出力を処理の途中に挿し込んでみたところ、リンク先に対応したコントローラが動作していないことが判明しました。(Test.javaのコンソール出力処理がまったく行われない)
・SpringBootやThymeleafの入門サイトを多数確認し、リンクや@RequestMappingの引数を何度も書き直してみましたが、いずれの方法でも症状は改善しませんでした。
補足情報(FW/ツールのバージョンなど)
eclipse photon
gradle 4.10.2
まだ回答がついていません
会員登録して回答してみよう