springboot 增加对jsp的支持,具体步骤

现在前后的分离的,一般springboot 就用来做后台restful 接口,那么如果要前后端合并在springboot呢?可以通过下面几个简单的步骤,增加对jsp的支持。

(1)pom增加依赖:

		<!--springboot tomcat jsp 支持开启-->
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<scope>compile</scope>
		</dependency>
(2)配置jsp的放置位置

a.如果用的是yml配置,如下配置:


spring:
    mvc:
      view:
        prefix: /WEB-INF/jsp/
        suffix: .jsp
b.如果用的是properties配置,如下配置:

spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp

spring.thymeleaf.cache=false    //这个是关闭thymeleaf缓存
spring.thymeleaf.enabled = false  //关闭thymeleaf模板

(3)springboot 利用工具搭建时,是没有webAPP等目录的,需要手动创建以下目录:


(4)如上,已经是完成了。第四步,写个controller访问。注意别加注解@ResponeBody 或者@RestController

@Controller
public class IndexController {
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}



猜你喜欢

转载自blog.csdn.net/neymar_jr/article/details/79107834