在使用springboot框架裏使用jsp的時候,頁面模板使用jsp在pom.xnl中須要引入相關的依賴,不然在controller中沒法返回到指定頁面java
<!-- servlet 依賴. --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <!-- JSTL 依賴. --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!-- tomcat 的支持. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- -jasper依賴.(暫時不知道幹啥的) --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency>
spring.mvc.view.prefix=/WEB-INF/jsp spring.mvc.view.suffix=.jsp
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import com.xujie.service.CountService; @Controller public class CountController { @Autowired private CountService countService; //跳轉頁面 @GetMapping("/index") public String goIndex() { return "index"; } }
略web