springboot-集成 警JSP

springboot-集成 警JSP

1,修改 pom 文件

1,把 pom 打包方式改成 打 war 包

<packaging>war</packaging>

2,添加依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

2,配置 application.properties 文件

配置视图解析器

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

3,controller 层

package com.test.freemarker;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 */
@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index(ModelMap map){
        map.addAttribute("name", "张三");
        return "index";
    }
}

你可能感兴趣的:(springBoot)