zoukankan      html  css  js  c++  java
  • springboot整合jsp模板

    springboot整合jsp模板

    在使用springboot框架里使用jsp的时候,页面模板使用jsp在pom.xnl中需要引入相关的依赖,否则在controller中无法返回到指定页面

    〇、搭建springboot框架

    一、添加jsp相关的依赖如下:

    <!-- 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
    

    三、controller

    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-INF/jsp下编写index.jsp页面

  • 相关阅读:
    传统工业制造商Opto 22宣布加入Linux基金会
    Android Stack
    An Overview of the Android Architecture (Android Studio)
    基于嵌入式操作系统的物联网安全
    什么是雾计算?它与云计算有什么区别?
    《速度与激情8》中的信息安全技术
    专利驳回的三大基本原因
    专利
    【习题 4-2 Uva201】Squares
    【习题4-1 Uva1589】Xiangqi
  • 原文地址:https://www.cnblogs.com/xujie09/p/8462392.html
Copyright © 2011-2022 走看看