标签:
上一篇文章讲了,创建了第一个springboot的项目,现在讲一下springboot的web+freemarker的项目;
1、首先引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>${spring.boot.version}</version> </dependency>
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Created by LK on 2016/5/7. */ @SpringBootApplication public class SampleWebFreeMarkerApplication { public static void main(String[] args) { SpringApplication.run(SampleWebFreeMarkerApplication.class,args); } }
import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import java.util.Date; import java.util.Map; /** * Created by LK on 2016/5/7. */ @Controller public class WebContrpller { @Value("${application.message:1234556677}") private String message = "hi,hello world......"; @RequestMapping("/") public String web(Map<String,Object> model){ model.put("time",new Date()); model.put("message",this.message); return "web";//返回的内容就是templetes下面文件的名称 } }
4.1 error.ftl
<!DOCTYPE html> <html lang="en"> <body> Something wrong: ${status} ${error} </body> </html>
<!DOCTYPE html> <html lang="en"> <body> Date: ${time?date} <br> Time: ${time?time} <br> Message: ${message} </body> </html>
5、启动 SampleWebFreeMarkerApplication ,在浏览器上面输入 http://127.0.0.1:8080/ 即可输出页面如下:
我的第二个springboot项目 web+freemarker
标签:
原文地址:http://blog.csdn.net/lk10207160511/article/details/51336791