开启Spring Boot

2017-08-10

Spring Boot是在Spring框架上创建的一个全新的框架,其设计目的是简化Spring应用的搭建和开发过程。开启Spring Boot有许多种方法可供选择,这里仅介绍使用http://start.spring.io/来构建一个简单的Spring Boot项目。

Read More »


Spring+Thymeleaf3国际化

2017-08-07

Spring+Thymeleaf3国际化配置国际化过程很简单,只需要在src/main/resources路径下定义不同语言环境的配置文件就好了,配置文件需以message开头,加上语言缩写后缀。

比如定义一个英文配置:src/main/resources/message_en.properties;中文环境:src/main/resources/message_zh_CN.properties;默认配置(就是都没匹配上的时候采用):src/main/resources/message.properties。

定义一个简单的HTML页面用于测试:

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>home</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p data-th-utext="#{home.welcome}">home</p>
</body>
</html>

Read More »

Spring4中配置Thymeleaf3视图

2017-08-06

引入必要的依赖文件:

1
2
3
4
5
6
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>

Read More »

Spring4配置多数据源

2017-08-05

Spring在每次操作数据库的时候都会通过AbstractRoutingDataSource类中的determineTargetDataSource()方法获取当前数据源,所以可以通过继承AbstractRoutingDataSource并重写determineTargetDataSource()方法来实现多数据源的配置。

定义一个DynamicDataSource类,继承AbstractRoutingDataSource:

1
2
3
4
5
6
7
8
9
package cc.mrbird.datasource;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
return DatabaseContextHolder.getCustomerType();
}
}

Read More »

Spring中使用@Scheduled注解任务调度

2017-08-04

spring-context包里提供的@Scheduled注解可以很方便的实现定时任务,在引入spring-context依赖后,在Spring xmlns中加入:

1
xmlns:task="http://www.springframework.org/schema/task"

然后在xsi:schemaLocation中加入:

1
2
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd

Read More »

Spring4中使用Quartz

2017-08-02

Spring提供了几个类用于简化在Spring中使用Quartz任务调度。这里使用的Spring版本为4.3.5,Quartz版本为2.2.1。

除了搭建Spring MVC的几个依赖外,还需引入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>

Read More »

Quartz guide

2017-08-01

Quartz是一款开源的任务调度框架,对任务调度过程进行了高度的抽象,包含调度器(Scheduler),任务(Job)和触发器(Trigger)。Quartz在org.quartz.*中通过接口和类对这三个概念进行了描述(这里使用的Quartz版本为1.8.6):

Job:一个简单的接口,只包含一个void execute(JobExecutionContext context)抽象方法。实际开发中,通过实现该接口来定义需要执行的任务。JobExecutionContext提供了调度上下文信息。

1
2
3
4
public interface Job {
void execute(JobExecutionContext context)
throws JobExecutionException;
}

Read More »

初识Flex布局

2017-07-21

传统的CSS布局方法中,一般使用float属性和display:table来实现布局,但在使用的过程中总有种无法随心所欲的感觉,元素的位置摆放总是显得不是那么的直观,而Flexbox很好的解决了这个问题。Flexbox俗称弹性盒子模型,在开始使用Flexbox之前,首先要声明一个Flex容器(Flex Container)。而Flex容器中的元素称为Flex项目(Flex Item)。

Read More »


1…262728…45
Hosted  by  Coding Pages
MrBird
MrBird

A simple blog, code repository, just keep blogging

14 Archives 2 Labels
  • 🏠 Home
  • 📦 Archives
  • 🔖 Labels
  • 👬 Friends
  • 🔍 Search
  •   UV    PV 
    0