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映射路径
Copyright © 2023 leiyu.cn. All Rights Reserved. 磊宇云计算 版权所有 许可证编号:B1-20233142/B2-20230630 山东磊宇云计算有限公司 鲁ICP备2020045424号
磊宇云计算致力于以最 “绿色节能” 的方式,让每一位上云的客户成为全球绿色节能和降低碳排放的贡献者