通过springboot搭建web项目

1、准备工作有:jdk1.7 +,eclipse,maven 等等

2、通过spring boot 官网build基于web的一个简单demo 或者自己手动新建maven项目

地址:https://start.spring.io/   截图如下:

基于springboot 之jsp章节

3、将下载好的demo导入到eclipse中;

4、在pom.xml中引入jsp编辑器相关包依赖

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

5、配置application.properties文件中关于jsp配置信息

#springboot into JSP PATH :src/main/webapp
spring.mvc.view.prefix=/indexs/
spring.mvc.view.suffix=.jsp

6、编写Controller

@RequestMapping(value = "/hello",method = RequestMethod.GET)
public ModelAndView hello(ModelAndView mv) throws Exception{
    mv.addObject("user", "zhangsan");
    mv.setViewName("index");
    return mv;
}

7、新建src/main/webapp/indexs文件夹,并在下新建index.jsp页面信息

<body>
<h1>hello ${user}</h1>
</body>

8、启动springboot启动类,并访问http://localhost:8080/hello,效果图:

基于springboot 之jsp章节


相关文章: