Spring Boot: 开发web 应用 - 01 创建项目

Spring Boot非常适合Web应用程序开发。使用spring-boot-starter-web模块快速启动和运行。 其中使用嵌入式Tomcat,Jetty或Undertow轻松创建自包含的HTTP服务器

Spring Boot支持多种方式来创建一个项目:

  1. 使用curl命令 Using curl
  2. 使用Spring Boot CLI 命令行工具 Using CLI
  3. https://spring.io/ 在线生成项目
  4. 使用Spring的集成开发工具

创建Spring Boot项目:

这里简单在线生成一个项目; 直接访问https://start.spring.io/,填写Group和Artifact,添加Web和 Freemarker两个依赖项。
这里写图片描述

Spring Boot 支持的可以替换JSP的,view engine包括: Thymeleaf, Groovy Markup Templates, Freemarker, Velocity. (As of Spring Framework 4.3, Velocity support has been deprecated due to six years without active maintenance of the Apache Velocity project. ) 除了Velocity 以外,其他根据个人爱好自助选择。

添加HomeController

@Controller
public class HomePageController {

    @RequestMapping("/")
    public String home(){
        return "index";
    }
}

添加前端页面的模板

采用开源bootstrap的H5 模板:awesome template
默认页面文件需要添加至/src/main/resources/templates 下面;静态资源文件的位置在/src/main/resources/static (或者/src/main/resources/public)下面。
目录结构如下:
这里写图片描述

运行SpringBootApplication主程序;访问http://localhost:8080验证。 截止目前,没有任何定制的情况下,我们可以看到Awesome 的模板页面。

github repo

spring-boot-trail-static-content tags/ootb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值