【发布时间】:2018-03-02 15:28:40
【问题描述】:
我是 Thymeleaf 的新手。我正在使用 thymeleaf 在视图部分创建一个 spring-boot 应用程序。
请在我的 pom.xml 文件下方找到[仅依赖项部分]:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
我在以下位置创建了一个 application.properties 文件:src/main/resources
server.port = 8086
spring.mvc.static-path-pattern=/resources/**
spring.thymeleaf.prefix=/WEB-INF/views/
spring.thymeleaf.suffix=.html
以下是我的 Boot Application Main 类:
@SpringBootApplication
@ComponentScan(basePackages="<common package structure>")
public class AdvMain extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AdvMain.class);
}
public static void main(String[] args) {
SpringApplication.run(AdvMain.class, args);
}
}
我有一个控制器类如下:
@Controller
public class HomeController {
@RequestMapping(path = "/info", method = { RequestMethod.GET, RequestMethod.POST })
public String info(Model model) {
model.addAttribute("message", "Thymeleaf");
return "info";
}
@RequestMapping(path = "/home", method = RequestMethod.GET)
public String index() {
return "index";
}
}
当我调用以下网址时:
http://localhost:8086/AddViewer/home
我收到页面未找到错误。
请在下面找到我的 tomcat 控制台日志:
Mapped "{[/home],methods=[GET]}" onto public java.lang.String <package_Structure>.HomeController.index()
Mapped "{[/info],methods=[GET || POST]}" onto public java.lang.String <package_Structure>.HomeController.info(org.springframework.ui.Model)
Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Tomcat started on port(s): 8086 (http)
FrameworkServlet 'dispatcherServlet': initialization completed in 29 ms
No mapping found for HTTP request with URI [/AddViewer/home] in DispatcherServlet with name 'dispatcherServlet'
谁能为此提供任何合适的解决方案???
【问题讨论】:
标签: java spring spring-boot thymeleaf