Springboot的配置文件和模版thymeleaf

Springboot介绍
首先声明,Spring Boot不是一门新技术,所以不用紧张。从本质上来说,Spring
Boot就是Spring,它做了那些没有它你也会去做的Spring
Bean配置。它使用“习惯优于配置”(项目中存在大量的配置,此外还内置了一个习惯性
的配置,让你无需手动进行配置)的理念让你的项目快速运行起来。使用Spring
Boot很容易创建一个独立运行(运行jar,内嵌Servlet容器)、准生产级别的基于Spring
框架的项目,使用Spring Boot你可以不用或者只需要很少的Spring配置。

☆ http://tengj.top/2017/04/24/springboot0/

第一个SpringBoot :HelloWorld
网页介绍
http://start.spring.io/

pom.xml解析(父级依赖)

org.springframework.boot
spring-boot-starter-parent
1.5.1.RELEASE

3.应用入口类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Chapter1Application {

@RequestMapping("/")
public String index(){
	return "Hello Spring Boot";
}
public static void main(String[] args) {
	SpringApplication.run(Chapter1Application.class, args);
}

}

4.解决报错问题

org.hibernate
hibernate-validator
5.3.0.Final

SpringBoot原理

Banner
如果我们想改动,那么只需要在src/main/recesources下新建一个banner.txt文件
实际上Spring Boot在这个位置,放了一个彩蛋,我们是可以自定义这个图标的。

我们可以在resource目录下面放入一个banner.txt文件,
Spring Boot启动项目的时候就会优先启动这个文件中的内容。

http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20

SpringBoot配置文件(application.properties)
http://tengj.top/2017/02/28/springbootconfig/

mybatis
#指定bean所在包
mybatis.type-aliases-package=com.dudu.domain
#指定映射文件
mybatis.mapperLocations=classpath:mapper/*.xml

spring.datasource.url=jdbc:mysql://localhost:3306/work1?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

SpringBoot模版(templates:thymeleaf)
https://blog.csdn.net/qq_32923745/article/details/78257686
Jar包

org.springframework.boot
spring-boot-starter-thymeleaf

配置文件
spring.thymeleaf.cache=true
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.excluded-view-names=
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

头文件导入

4.文本显示

5.链接显示

6.for循环表达(3种)
遍历数组

遍历数组:详细版本

循环指定次数

6.条件表达式

7 switch


匹配1
匹配2
默认匹配

8.其他作用域访问
${param.x} 返回名为x 的 request参数。(可能有多个值)
${session.x} 返回名为x的Session参数。
${application.x} 返回名为 servlet application context 的参数。

9.if
th:if="${xx} lt ‘x’"

gt:great than(大于)>
ge:great equal(大于等于)>=
eq:equal(等于)==
lt:less than(小于)<
le:less equal(小于等于)<=
ne:not equal(不等于)!=

SpringBoot静态文件(static:js、css)
Maven下载失败

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

/**

  • 删除maven下载失败的目录
  • 先搜索 存在 lastUpdated的文件(即jar文件等),
  • 然后再删除此文件的目录

*/
public class DeleteMavenDownloadfailedFile {

/**声明统计文件个数的变量*/ 
static int countFiles = 0;

/**声明统计文件夹的变量*/ 
static int countFolders = 0;

/**
 *递归查找包含关键字的文件
 */ 
public static File[] searchFile(File folder, final String keyWord) {

	File[] subFolders = folder.listFiles(new FileFilter() {// 运用内部匿名类获得文件
				public boolean accept(File pathname) {// 实现FileFilter类的accept方法
					if (pathname.isFile()) {// 如果是文件
						countFiles++;
					} else {
						// 如果是目录
						countFolders++;
					}
					if (pathname.isDirectory()
							|| (pathname.isFile() && pathname.getName().toLowerCase().contains(keyWord.toLowerCase()))) {// 目录或文件包含关键字
						return true;
					}
					return false;
				}
			});

	List<File> result = new ArrayList<File>();// 声明一个集合
	for (int i = 0; i < subFolders.length; i++) {// 循环显示文件夹或文件
		if (subFolders[i].isFile()) {// 如果是文件则将文件添加到结果列表中
			result.add(subFolders[i]);
		} else {// 如果是文件夹,则递归调用本方法,然后把所有的文件加到结果列表中
			File[] foldResult = searchFile(subFolders[i], keyWord);
			for (int j = 0; j < foldResult.length; j++) {// 循环显示文件
				result.add(foldResult[j]);// 文件保存到集合中
			}
		}
	}
	File files[] = new File[result.size()];// 声明文件数组,长度为集合的长度
	result.toArray(files);// 集合数组化
	return files;
}


public static File[] find(String root, String keyword) {
	File folder = new File(root);// 默认目录
	if (!folder.exists()) {// 如果文件夹不存在
		System.out.println("目录不存在:" + folder.getAbsolutePath());
		return null;
	}
	File[] result = searchFile(folder, keyword);// 调用方法获得文件数组

	return result;
}

/**
 * 删除文件和目录
 * 
 * 注意:根据业务场景,此方法没有采用递归删除
 * 
 * @param file
 */
public static void delete(File file) {
	if (file.exists()) {
		if (file.isFile()) {
			boolean bb = file.delete();
			System.out.println(file.getAbsolutePath() + " 删除状态:" + bb);
		} else if (file.isDirectory()) {
			File files[] = file.listFiles();
			for (int i = 0; i < files.length; i++) {
				File _file = files[i];
				boolean bb = _file.delete();
				System.out.println("      " + _file.getAbsolutePath() + " 删除状态:" + bb);
			}
		}
		boolean bb = file.delete();
		System.out.println(file.getAbsolutePath() + " 删除状态:" + bb);
	} else {
		System.out.println("所删除的文件不存在!" + file.getAbsolutePath());
	}
}

public static void main(String[] args) {
	String root = "E:\\lee\\maven";
	String keyword = "lastUpdated";

	File[] result = find(root, keyword);
	if (result == null ) {
		return;
	}
	if (result.length == 0) {
		System.out.println("查找文件为 0");
		return;
	}
	
	System.out.println("在 " + root + " 以及所有子文件时查找对象" + keyword);
	System.out.println("查找了" + countFiles + " 个文件," + countFolders + " 个文件夹,共找到 " + result.length + " 个符合条件的文件:");
	for (int i = 0; i < result.length; i++) {// 循环显示文件
		File file = result[i];
		delete(new File(file.getParentFile().getAbsolutePath()));
		// System.out.println(file.getAbsolutePath() +
		// " == "+file.getParentFile().getAbsolutePath());// 显示文件绝对路径
	}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值