项目结构
1.引入依赖
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>echarts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>echarts</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>8.0.11</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--beetl-->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.9.3</version>
</dependency>
<!-- echarts-java映射类库 -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>ECharts</artifactId>
<version>3.0.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
config
BeetlConfig
package com.example.echarts.config;
import com.example.echarts.properties.BeetlProperties;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* web 配置类
*
* @author fengshuonan
* @date 2016年11月12日 下午5:03:32
*/
@Configuration
public class BeetlConfig {
@Autowired
BeetlProperties beetlProperties;
/**
* beetl的配置
*/
@Bean(initMethod = "init")
public BeetlConfiguration beetlConfiguration() {
BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(BeetlConfig.class.getClassLoader(), beetlProperties.getPrefix()));
beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
return beetlConfiguration;
}
/**
* beetl的视图解析器
*/
@Bean
public BeetlSpringViewResolver beetlViewResolver() {
BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
beetlSpringViewResolver.setConfig(beetlConfiguration());
beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
beetlSpringViewResolver.setOrder(0);
return beetlSpringViewResolver;
}
}
BeetlConfiguration
package com.example.echarts.config;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
/**
* beetl拓展配置,绑定一些工具类,方便在模板中直接调用
*
* @author stylefeng
* @Date 2018/2/22 21:03
*/
public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
@Override
public void initOther() {
}
}
properties
package com.example.echarts.properties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import java.util.Properties;
/**
* beetl配置(如果需要配置别的配置可参照这个形式自己添加)
*
* @author fengshuonan
* @date 2017-05-24 20:37
*/
@Configuration
@ConfigurationProperties(prefix = BeetlProperties.BEETLCONF_PREFIX)
public class BeetlProperties {
public static final String BEETLCONF_PREFIX = "beetl";
private String delimiterStatementStart;
private String delimiterStatementEnd;
private String resourceTagroot;
private String resourceTagsuffix;
private String resourceAutoCheck;
@Value("${spring.mvc.view.prefix}")
private String prefix;
public Properties getProperties() {
Properties properties = new Properties();
if (!StringUtils.isEmpty(delimiterStatementStart)) {
if (delimiterStatementStart.startsWith("\\")) {
delimiterStatementStart = delimiterStatementStart.substring(1);
}
properties.setProperty("DELIMITER_STATEMENT_START", delimiterStatementStart);
}
if (!StringUtils.isEmpty(delimiterStatementEnd)) {
properties.setProperty("DELIMITER_STATEMENT_END", delimiterStatementEnd);
} else {
properties.setProperty("DELIMITER_STATEMENT_END", "null");
}
if (!StringUtils.isEmpty(resourceTagroot)) {
properties.setProperty("RESOURCE.tagRoot", resourceTagroot);
}
if (!StringUtils.isEmpty(resourceTagsuffix)) {
properties.setProperty("RESOURCE.tagSuffix", resourceTagsuffix);
}
if (!StringUtils.isEmpty(resourceAutoCheck)) {
properties.setProperty("RESOURCE.autoCheck", resourceAutoCheck);
}
return properties;
}
public String getPrefix() {
return prefix;
}
public String getDelimiterStatementStart() {
return delimiterStatementStart;
}
public void setDelimiterStatementStart(String delimiterStatementStart) {
this.delimiterStatementStart = delimiterStatementStart;
}
public String getDelimiterStatementEnd() {
return delimiterStatementEnd;
}
public void setDelimiterStatementEnd(String delimiterStatementEnd) {
this.delimiterStatementEnd = delimiterStatementEnd;
}
public String getResourceTagroot() {
return resourceTagroot;
}
public void setResourceTagroot(String resourceTagroot) {
this.resourceTagroot = resourceTagroot;
}
public String getResourceTagsuffix() {
return resourceTagsuffix;
}
public void setResourceTagsuffix(String resourceTagsuffix) {
this.resourceTagsuffix = resourceTagsuffix;
}
public String getResourceAutoCheck() {
return resourceAutoCheck;
}
public void setResourceAutoCheck(String resourceAutoCheck) {
this.resourceAutoCheck = resourceAutoCheck;
}
}
yml
server:
port: 10086
################### beetl配置 ###################
beetl:
delimiter-statement-start: \@ #开始结束标签(yaml不允许@开头)
delimiter-statement-end: null
resource-tagroot: common/tags #自定义标签文件Root目录和后缀
resource-tagsuffix: tag
resource-auto-check: true #是否检测文件变化,开发用true合适,但线上要改为false
spring:
mvc:
static-path-pattern: /static/**
view:
prefix: /WEB-INF/view
http:
converters:
preferred-json-mapper: fastjson
devtools:
restart:
enabled: false #是否开启开发者工具(true/false)
additional-paths: src/main/java
exclude: static/**,WEB-INF/view/**
aop:
proxy-target-class: true #false为启用jdk默认动态代理,true为cglib动态代理
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/echarts?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false&autoReconnect=true
username: root
password: 123
filters: log4j,wall,mergeStat
mybatis:
mapper-locations: classpath:mapping/**/*.xml
type-aliases-package: com.example.echarts.controller
创建webapp目录
至此就可为所欲为