关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

springboot集成jsp的Demo实现

发布时间:2023-06-30 23:28:41

1.创建一个maven web项目

2.添加springboot和jsp相关依赖

 org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE  junit junit 3.8.1 test   org.springframework.boot spring-boot-starter-web      org.springframework.boot spring-boot-starter-tomcat   org.apache.tomcat.embed tomcat-embed-jasper

   

3.在application.properties配置文件中添加配置

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

   

4.创建一个controller

@EnableAutoConfiguration @ComponentScan(basePackages="com.vhukze.controller") @RestController public class JspDemoController {   @RequestMapping("/toJsp")  public ModelAndView toJsp() {  return new ModelAndView("index");  }   public static void main(String[] args) {  SpringApplication.run(JspDemoController.class, args);  } }

   

5.在src/main下新建webapp目录,在webapp下面创建配置的路径

Hello World!

   

6.启动项目访问controller映射路径


/template/Home/leiyu/PC/Static