功能:根据要求的文档格式,每天定时从各数据源查到数据后填充到文档模板并生成doc文档,自动发送到相关人员邮箱。
目录
一、pom.xml及依赖包;
二、
SpringBoot实现命令行方式应用;
三、SpringBoot+Mybatis获取数据;
四、SpringBoot+Freemarker生成日报文档;
五、SpringBoot+SimpleMail自动发邮件;
六、打包方法
一、pom.xml及依赖包
(一)SpringBoot核心
(二)数据库JDBC连接
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
(三)MySQL
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
(四)Mybatis
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
(五)FreeMarker
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
(六)SimpleMail
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
(七)jacob
<dependency>
<groupId>jacob</groupId>
<artifactId>jacob</artifactId>
<version>1.17</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jacob.jar</systemPath>
</dependency>
(八)Junit
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
(九)构建时需扫描资源目录下的文件夹
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/templates/*.ftl</include>
</includes>
</resource>
</resources>
二、
SpringBoot实现命令行方式应用
在SpringBoot 工程的启动类上实现 org.springframework.boot.CommandLineRunner接口的run方法即可:主程序实现CommandLineRunner接口,然后在run方法里写程序逻辑:
public class OpsDailyApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(OpsDailyApplication.class, args);
}
。。。
public void run(String... args) {
/**写程序逻辑**/
}
这样
能够利用 SpringBoot的其他所有功能。
三、
SpringBoot+Mybatis获取数据
(一)配置
数据库信息