一、spring boot 1.5.4入门(web+freemarker)
1.配置maven文件pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.hdwang</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.0-SNAPSHOT</version> <name>spring-boot-test</name>
<description>project for test Spring Boot</description> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent> <dependencies>
<!-- Add typical dependencies for a web application -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> <!-- auto redeploy -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency> <!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
2.文件结构(static/templates/application.properties/logback.xml的名称都是约定好了的,只可以使用某几个名称,具体参考spring boot官方文档,下面的名称是其中一种配置方式)

3.建立启动类(放在顶层,子层(下级文件夹)的类方可被扫描注入)
@SpringBootApplication
public class Application { /**
* main function
* @param args params
*/
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
4.建立controller(在Application类的下级目录中)
@Controller
@RequestMapping("/common")
public class Common { @Value("${msg:Welcome!}")
private String msg; /**
* get a page
* @return a page with name called return value
*/
@RequestMapping("login")
public String getLoginPage(ModelMap map){
map.put("welcomeMsg",this.msg);
return "login";
} }
5.建立网页模板login.ftl(freemarker必须使用ftl后缀,被这个坑了好久!js/css啥的都放在相应文件夹下,注意访问路径中不带/static,也被这个坑了好久!)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>login</title> <link href="/css/home.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="/js/home.js"></script>
</head>
<body>
<h1>login page</h1>
<h2>${welcomeMsg}</h2>
<form>
<div>
<label>用户名:<input type="text" id="username"/></label>
</div>
<div>
<label>密码:<input type="password"/></label>
</div>
<div>
<input type="submit" value="提交"/>
<input type="reset" value="重置" />
</div>
</form>
</body>
</html>
6.应用配置文件编写
新建application.properties文件并添加以下内容
msg=Ladies and gentleman,Welcome!
7.启动运行
浏览器中访问:http://localhost:8080/common/login

8.部署
mvn package 打个包
java -jar xxx.jar 运行这个包即可
一、spring boot 1.5.4入门(web+freemarker)的更多相关文章
- Spring Boot 2.x 快速入门(下)HelloWorld示例详解
上篇 Spring Boot 2.x 快速入门(上)HelloWorld示例 进行了Sprint Boot的快速入门,以实际的示例代码来练手,总比光看书要强很多嘛,最好的就是边看.边写.边记.边展示. ...
- Spring Boot从入门到精通之:一、Spring Boot简介及快速入门
Spring Boot Spring Boot 简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来 ...
- 如何优雅的关闭基于Spring Boot 内嵌 Tomcat 的 Web 应用
背景 最近在搞云化项目的启动脚本,觉得以往kill方式关闭服务项目太粗暴了,这种kill关闭应用的方式会让当前应用将所有处理中的请求丢弃,响应失败.这种形式的响应失败在处理重要业务逻辑中是要极力避免的 ...
- spring boot集成redis基础入门
redis 支持持久化数据,不仅支持key-value类型的数据,还拥有list,set,zset,hash等数据结构的存储. 可以进行master-slave模式的数据备份 更多redis相关文档请 ...
- spring boot 初试,springboot入门,springboot helloworld例子
因为项目中使用了spring boot ,之前没接触过,所以写个helloworld玩玩看,当做springboot的一个入门例子.搜索 spring boot.得到官方地址:http://proje ...
- Spring Boot微服务架构入门
概述 还记得在10年毕业实习的时候,当时后台三大框架为主流的后台开发框架成软件行业的标杆,当时对于软件的认识也就是照猫画虎,对于为什么会有这么样的写法,以及这种框架的优势或劣势,是不清楚的,Sprin ...
- Spring Boot 2.x 快速入门(上)HelloWorld示例
本文重点 最近决定重新实践下Spring Boot的知识体系,因为在项目中遇到的总是根据业务需求走的知识点,并不能覆盖Spring Boot完整的知识体系,甚至没有一个完整的实践去实践某个知识点.最好 ...
- 2、Spring Boot 2.x 快速入门
1.2 Spring Boot 快速入门 1.2.1 开发环境和工具 JDK 1.8+:Spring Boot 2.x 要求 JDK 1.8 环境及以上版本.另外,Spring Boot 2.x 只兼 ...
- Spring Boot第五弹,WEB开发初了解~
持续原创输出,点击上方蓝字关注我吧 目录 前言 Spring Boot 版本 前提条件(必须注意) 添加依赖 第一个接口开发 如何自定义tomcat的端口? 如何自定义项目路径? JSON格式化 日期 ...
随机推荐
- mysql 配置 root 远程访问
来源: https://www.cnblogs.com/24la/p/mariadb-remoting-access.html 首先配置允许访问的用户,采用授权的方式给用户权限 GRANT ALL P ...
- NAND Flash底层原理,SLC MLC TLC比较
NAND-Flash 的存储原理 固态硬盘最小单元的基本架构如下: 我们知道计算机中所有的信息储存最终都必须回归到 0与1,原则上,只要存储单元能提供两种或两种以上可供辨识的状态,便可以拿来纪录数据. ...
- Svn 提示错误:previous operation has not finished 解决方案
svn提交遇到恶心的问题,可能是因为上次cleanup中断后,进入死循环了. 解决方案: 找到你项目的.svn文件,查看是否存在wc.db 网上下载SQLite Expert工具,手动打开wc.db, ...
- 记录:tf.saved_model 模块的简单使用(TensorFlow 模型存储与恢复)
虽然说 TensorFlow 2.0 即将问世,但是有一些模块的内容却是不大变化的.其中就有 tf.saved_model 模块,主要用于模型的存储和恢复.为了防止学习记录文件丢失或者蠢笨的脑子直接遗 ...
- GitHub 新手教程 四,Git GUI 新手教程(1),OpenSSH Public Key
1,从开始菜单 启动 Git GUI,或者运行: D:\soft\Git\cmd\git-gui.exe(D:\soft\Git 为您的 GitHub 安装文件夹) 2,获取 SSH 密钥: 3,点击 ...
- PBFT_拜占庭容错算法
根据论文<Practical Byzantine Fault Tolerance and Proactive Recovery>整理 Practical byzantine fault t ...
- PHP学习 Object Oriented 面向对象 OO
定义类class class_name [extends partclass_name]{public private protected var property_name = value;publ ...
- Android Studio发布Release版本之坑--Unknown host 'd29vzk4ow07wi7.cloudfront.net'
使用Android Studio发布Release版本时,出现Unknown host 'd29vzk4ow07wi7.cloudfront.net'...错误. 解决方法:修改本机的DNS为8.8. ...
- This is me
This is me 爱琴棋 爱书画 也爱格物 爱跋山 爱涉水 也爱深林 This is me. 刘伯承的诗词有曰“高耸入云”,于是“李入云”便成为了我一生的标记,也造就了一个时而安静,时而疯狂的我 ...
- 【MOOC EXP】Linux内核分析实验五报告
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 分析system_call中断处理过程 ...