我在春季啓動新來渲染JSP,我想先從一個簡單的例子,但似乎沒有任何工作 這是我的控制器:無法使用Spring引導
Package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class testController {
RequestMapping("view/aboutus")
public String greeting(Model model) {
model.addAttribute("name", "azertyyyy");
return "aboutus"; }}
,這是JSP視圖:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE>
<html> <body> ${name}
<p>hello world</p> </body></html>
我添加所需依賴關係:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
和我添加前綴和後綴在application.properties
當我運行應用程序只有你好世界顯示在沒有名稱變量的視圖,在這裏搜索後,我將視圖目錄從src/main/webapp/view更改爲src/main/resource /模板,但彈簧引導無法找到視圖
我可以添加一些細節,如果有什麼不明確 –