如何在SpringBoot中使用JSP
1个回答
展开全部
1. pom.xm加入支持JSP依赖org.apache.tomcat.embedtomcat-embed-jasperprovidedjavax.servlet.jsp.jstljstl-api1.22. src/main/resources/application.properties文件配置JSP传统Spring MVCview关联# MVCspring.view.prefix=/WEB-INF/views/spring.view.suffix=.jsp3. 创建src/main/webapp/WEB-INF/views目录JSP文件放Hello ${name}4. 编写Controllerpackage com.chry.study;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controller@EnableAutoConfigurationpublic class SampleController {@RequestMapping("/hello")public ModelAndView getListaUtentiView(){ModelMap model = new ModelMap();model.addAttribute("name", "Spring Boot");return new ModelAndView("hello", model);}}5. 编写Application类package com.chry.study;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;@SpringBootApplicationpublic class WebApplication extends SpringBootServletInitializer {@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder application) {return application.sources(WebApplication.class);}public static void main(String[] args) throws Exception {SpringApplication.run(WebApplication.class, args);}}如何在SpringBoot中使用JSP
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询