1、编写controller
@Controller
public class UserController {
@RequestMapping("/user/detail")
public @ResponseBody Object userDetail(){
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 1001);
map.put("username", "zhangsan");
return map;
}
}
2、添加依赖
<!--Springboot内嵌tomcat解析jsp的依赖-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--在build标签中指定编译的位置-->
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>*.*</include>
</includes>
</resource>
</resources>