Spring Boot + Velocity 极简demo

1. 首先加入需要的maven依赖

<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.7.RELEASE</version>
</parent>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-velocity</artifactId>
</dependency>

2. Controller代码

@Controller
@RequestMapping("/index")
public class IndexController {

    @RequestMapping("/")
    public String index(ModelMap modelMap) {
        modelMap.addAttribute("name", "ruzun");
        return "index";
    }
}

3. vm页面

inde.vm

<html>
<body>
hello world, $name
</body>
</html>

index.vm页面放在/resources/templates/ 下, 这是默认位置

这里写图片描述

4. 运行

boot-web

猜你喜欢

转载自blog.csdn.net/bruce128/article/details/79190688