springboot+itextpdf+thymeleaf+ognl根据静态模版文件实现动态生成pdf文件并导出demo

本文主要是介绍springboot+itextpdf+thymeleaf+ognl根据静态模版文件实现动态生成pdf文件并导出demo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

第一步:导入maven依赖

<!-- 导出为PDF依赖包 --><dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itext-asian</artifactId></dependency><dependency><groupId>com.itextpdf.tool</groupId><artifactId>xmlworker</artifactId><version>5.5.13.3</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>ognl</groupId><artifactId>ognl</artifactId><version>3.1.12</version></dependency>

第二步:制作thymeleaf静态模版文件并放置在resources目录下,可以自定义模版文件路径

如图所示

thymeleaf静态文件示例:
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"><head><meta charset="utf-8"/><title>xxxx模版</title><style>#mainTable {border-collapse: collapse;border-style: solid;border-width: 0.5pt;width: 100%;}#mainTable td{text-align: center;padding: 8px;border-style: solid;border-width: 0.5pt;}</style>
</head><body><table id="header" boder="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom:10px;margin-top:10px;"><tbody><tr><td id="img" rowspan="3"><img th:src="${xxxx}" style="border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;-ms-border-radius: 50%;-o-border-radius: 50%;width: 60%;height: 60%;"/></td><td id="mainTitle" colspan="5" th:text="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+${xxxx}" style="font-size: 30px;font-style: '+';font-weight: bold;padding-left:30%;padding-bottom:10px;"></td></tr><tr><td></td><td id="xxxx" colspan="5" th:text="${xxxx}+哈哈" style="font-size: 30px;font-style: '+';font-weight: bold;padding-left:45%;padding-top:10px;"></td></tr><tr><td></td><td id="xxxx" colspan="5" style="text-align:right;padding-right:0px;">xxxx: <span  th:text="${xxxx}"></span></td></tr></tbody></table><table id="mainTable"><tbody><tr><td>xxxx</td><td th:text="${xxxx}"></td><td>xxxx</td><td th:text="${xxxx}"></td><td>xxxx</td><td th:text="${xxxx} + ${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="2" th:text="${xxxx} + '/' + ${xxxx}"></td><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="5" style="text-align:left;" th:text="${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td><td>xxxx</td><td colspan="2" th:text="${xxxx}"></td></tr><tr><td height="250">xxxx</td><td colspan="5" style="text-align:left;" th:text="${xxxxx}"></td></tr><tr><td height="250">xxxx</td><td colspan="5" style="text-align:left;" th:text="${xxxx}"></td></tr><tr><td>xxxx</td><td colspan="5" style="text-align:left;"><img th:src="${xxxx}" style="width: 50%;height: 30%;"/></td></tr></tbody></table><div style="margin-top:40px;"><p>注:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p></div></body></html>

第三步:实现编写生成pdf与下载工具,注意区分项目格式是war包还是jar包,目前我这边是两套实现方案。

jar包的方案是否同样适用于war包,我这边没有尝试,有兴趣的可以自己尝试,然后在评论区分享一下。

1)在jar包环境下加载静态模版文件时的代码示例:

静态模版无需加载包含base64格式的图片内容时,可用以下代码处理:

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;/*** @author leon* @date 2023/8/15* @description pdf 模版下载工具**/
@Component
@Slf4j
public class PdfTemplateDownload {@Autowiredprivate ApplicationContext applicationContext;/*** 下载pdf模版* @param response* @param paramMap* @param templateFileName* @param outputFileName*/public void downloadPdfTemplate(HttpServletResponse response,Map<String, Object> paramMap,String templateFileName,String outputFileName) {try {// 创建基于类路径资源的模板解析器SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();resolver.setApplicationContext(applicationContext); // 你需要注入Spring的应用上下文resolver.setTemplateMode(TemplateMode.HTML);resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());resolver.setCacheable(true); // 在开发阶段设置为false,生产环境可改为trueresolver.setPrefix("classpath:/file/");resolver.setSuffix(".html");// 创建模版引擎TemplateEngine engine = new TemplateEngine();engine.setTemplateResolver(resolver);// 填充变量参数Context context = new Context();paramMap.forEach((k,v) -> context.setVariable(k, v));// 替换变量值String output = engine.process(templateFileName, context);// 设置导出文件名String exportName = "attachment;filename="+outputFileName;response.setHeader("Content-Disposition",new String(exportName.getBytes(StandardCharsets.UTF_8),"ISO8859-1"));response.setContentType("application/mspdf");response.setCharacterEncoding("utf-8");// 新建Document对象Document document = new Document(PageSize.A4);// 新建PdfWriter对象PdfWriter pdfWriter = PdfWriter.getInstance(document, response.getOutputStream());// 打开文档document.open();// 读取html文件内容InputStream htmlInputStream = new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8));// 使用XMLWorkerHelper将html内容转为pdfXMLWorkerHelper xmlWorkerHelper = XMLWorkerHelper.getInstance();xmlWorkerHelper.parseXHtml(pdfWriter, document, htmlInputStream, Charset.forName("UTF-8"), new AsianFontProvider());// 关闭文档document.close();// 关闭输入流htmlInputStream.close();// 关闭文件输出流IOUtils.closeQuietly(response.getOutputStream());}catch (IOException e) {log.error("", e);}catch (DocumentException e) {log.error("", e);}}/*** 用于中文显示的Provider*/class AsianFontProvider extends XMLWorkerFontProvider {@Overridepublic Font getFont(final String fontname, String encoding, float size, final int style) {try {BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);return new Font(bfChinese, size, style);}catch (Exception e) {}return super.getFont(fontname, encoding, size, style);}}}
若静态模版中有base64格式的图片信息,可换用下边的方法实现

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.Pipeline;
import com.itextpdf.tool.xml.XMLWorker;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import com.itextpdf.tool.xml.css.CssFilesImpl;
import com.itextpdf.tool.xml.css.StyleAttrCSSResolver;
import com.itextpdf.tool.xml.html.CssAppliersImpl;
import com.itextpdf.tool.xml.html.HTML;
import com.itextpdf.tool.xml.html.TagProcessorFactory;
import com.itextpdf.tool.xml.html.Tags;
import com.itextpdf.tool.xml.parser.XMLParser;
import com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline;
import com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline;
import com.itextpdf.tool.xml.pipeline.html.HtmlPipeline;
import com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;/*** @author leon* @date 2023/8/15* @description pdf 模版下载工具**/
@Component
@Slf4j
public class PdfTemplateDownload {@Autowiredprivate ApplicationContext applicationContext;/*** 下载pdf模版,用于模版中需要展示base64格式的图片信息* @param response* @param paramMap* @param templateFileName* @param outputFileName*/public void downloadPdfTemplateForBase64Img(HttpServletResponse response,Map<String, Object> paramMap,String templateFileName,String outputFileName) {try {// 创建基于类路径资源的模板解析器SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();resolver.setApplicationContext(applicationContext); // 你需要注入Spring的应用上下文resolver.setTemplateMode(TemplateMode.HTML);resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());resolver.setCacheable(true); // 在开发阶段设置为false,生产环境可改为trueresolver.setPrefix("classpath:/file/");resolver.setSuffix(".html");// 创建模版引擎TemplateEngine engine = new TemplateEngine();engine.setTemplateResolver(resolver);// 填充变量参数Context context = new Context();paramMap.forEach((k,v) -> context.setVariable(k, v));// 替换变量值String output = engine.process(templateFileName, context);// 设置导出文件名String exportName = "attachment;filename="+outputFileName;response.setHeader("Content-Disposition",new String(exportName.getBytes(StandardCharsets.UTF_8),"ISO8859-1"));response.setContentType("application/pdf");response.setCharacterEncoding("utf-8");// 新建Document对象Document document = new Document(PageSize.A4);// 新建PdfWriter对象PdfWriter pdfWriter = PdfWriter.getInstance(document, response.getOutputStream());// 打开文档document.open();// 自定义处理base64图片final TagProcessorFactory htmlTagProcessorFactory = Tags.getHtmlTagProcessorFactory();htmlTagProcessorFactory.removeProcessor(HTML.Tag.IMG);htmlTagProcessorFactory.addProcessor(new ImageTagProcessor(),HTML.Tag.IMG);final Charset charset = StandardCharsets.UTF_8;final CssFilesImpl cssFiles = new CssFilesImpl();cssFiles.add(XMLWorkerHelper.getInstance().getDefaultCSS());final StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);final HtmlPipelineContext hpc = new HtmlPipelineContext(new CssAppliersImpl(new AsianFontProvider()));hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(htmlTagProcessorFactory);final HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(document, pdfWriter));final Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);final XMLWorker worker = new XMLWorker(pipeline, true);final XMLParser p = new XMLParser(true, worker, charset);// 读取html文件内容InputStream htmlInputStream = new ByteArrayInputStream(output.getBytes(charset));p.parse(htmlInputStream, charset);// 关闭文档document.close();// 关闭输入流htmlInputStream.close();// 关闭文件输出流IOUtils.closeQuietly(response.getOutputStream());}catch (IOException e) {log.error("", e);}catch (DocumentException e) {log.error("", e);}}/*** 用于中文显示的Provider*/class AsianFontProvider extends XMLWorkerFontProvider {@Overridepublic Font getFont(final String fontname, String encoding, float size, final int style) {try {BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);return new Font(bfChinese, size, style);}catch (Exception e) {}return super.getFont(fontname, encoding, size, style);}}}

2)在war包环境下加载静态模版文件时的代码示例:

包含了静态模版中需要加载与不需要加载base64格式的图片内容时的两个方法实现示例:

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.Pipeline;
import com.itextpdf.tool.xml.XMLWorker;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import com.itextpdf.tool.xml.css.CssFilesImpl;
import com.itextpdf.tool.xml.css.StyleAttrCSSResolver;
import com.itextpdf.tool.xml.html.CssAppliersImpl;
import com.itextpdf.tool.xml.html.HTML;
import com.itextpdf.tool.xml.html.TagProcessorFactory;
import com.itextpdf.tool.xml.html.Tags;
import com.itextpdf.tool.xml.parser.XMLParser;
import com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline;
import com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline;
import com.itextpdf.tool.xml.pipeline.html.HtmlPipeline;
import com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext;
import com.wondersgroup.healthcloud.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.FileTemplateResolver;import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;/*** @author leon* @date 2023/8/15* @description pdf 模版下载工具**/
@Component
@Slf4j
public class PdfTemplateDownload {/*** 下载pdf模版* @param response* @param paramMap* @param templateFileName* @param outputFileName*/public void downloadPdfTemplate(HttpServletResponse response,Map<String, Object> paramMap,String templateFileName,String outputFileName) {try {URL url = PdfTemplateDownload.class.getClassLoader().getResource("file/"+templateFileName);if (ObjectUtils.isEmpty(url)) {throw new CommonException("下载模版文件缺失");}File htmlFile = new File(url.getPath());// 创建html文件解析器FileTemplateResolver resolver = new FileTemplateResolver();resolver.setTemplateMode(TemplateMode.HTML);resolver.setSuffix(".html");// 创建模版引擎TemplateEngine engine = new TemplateEngine();engine.setTemplateResolver(resolver);// 填充变量参数Context context = new Context();paramMap.forEach((k,v) -> context.setVariable(k, v));// 替换变量值String output = engine.process(htmlFile.getAbsolutePath(), context);// 设置导出文件名String exportName = "attachment;filename="+outputFileName;response.setHeader("Content-Disposition",new String(exportName.getBytes(StandardCharsets.UTF_8),"ISO8859-1"));response.setContentType("application/pdf");response.setCharacterEncoding("utf-8");// 新建Document对象Document document = new Document(PageSize.A4);// 新建PdfWriter对象PdfWriter pdfWriter = PdfWriter.getInstance(document, response.getOutputStream());// 打开文档document.open();// 读取html文件内容InputStream htmlInputStream = new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8));// 使用XMLWorkerHelper将html内容转为pdfXMLWorkerHelper xmlWorkerHelper = XMLWorkerHelper.getInstance();xmlWorkerHelper.parseXHtml(pdfWriter, document, htmlInputStream, Charset.forName("UTF-8"), new AsianFontProvider());// 关闭文档document.close();// 关闭输入流htmlInputStream.close();// 关闭文件输出流IOUtils.closeQuietly(response.getOutputStream());}catch (IOException e) {log.error("", e);}catch (DocumentException e) {log.error("", e);}}/*** 下载pdf模版,用于模版中需要展示base64格式的图片信息* @param response* @param paramMap* @param templateFileName* @param outputFileName*/public void downloadPdfTemplateForBase64Img(HttpServletResponse response,Map<String, Object> paramMap,String templateFileName,String outputFileName) {try {URL url = PdfTemplateDownload.class.getClassLoader().getResource("file/"+templateFileName);if (ObjectUtils.isEmpty(url)) {throw new CommonException("下载模版文件缺失");}File htmlFile = new File(url.getPath());// 创建html文件解析器FileTemplateResolver resolver = new FileTemplateResolver();resolver.setTemplateMode(TemplateMode.HTML);resolver.setSuffix(".html");// 创建模版引擎TemplateEngine engine = new TemplateEngine();engine.setTemplateResolver(resolver);// 填充变量参数Context context = new Context();paramMap.forEach((k,v) -> context.setVariable(k, v));// 替换变量值String output = engine.process(htmlFile.getAbsolutePath(), context);// 设置导出文件名String exportName = "attachment;filename="+outputFileName;response.setHeader("Content-Disposition",new String(exportName.getBytes(StandardCharsets.UTF_8),"ISO8859-1"));response.setContentType("application/pdf");response.setCharacterEncoding("utf-8");// 新建Document对象Document document = new Document(PageSize.A4);// 新建PdfWriter对象PdfWriter pdfWriter = PdfWriter.getInstance(document, response.getOutputStream());// 打开文档document.open();// 自定义处理base64图片final TagProcessorFactory htmlTagProcessorFactory = Tags.getHtmlTagProcessorFactory();htmlTagProcessorFactory.removeProcessor(HTML.Tag.IMG);htmlTagProcessorFactory.addProcessor(new ImageTagProcessor(),HTML.Tag.IMG);final Charset charset = StandardCharsets.UTF_8;final CssFilesImpl cssFiles = new CssFilesImpl();cssFiles.add(XMLWorkerHelper.getInstance().getDefaultCSS());final StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);final HtmlPipelineContext hpc = new HtmlPipelineContext(new CssAppliersImpl(new AsianFontProvider()));hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(htmlTagProcessorFactory);final HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(document, pdfWriter));final Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);final XMLWorker worker = new XMLWorker(pipeline, true);final XMLParser p = new XMLParser(true, worker, charset);// 读取html文件内容InputStream htmlInputStream = new ByteArrayInputStream(output.getBytes(charset));p.parse(htmlInputStream, charset);// 关闭文档document.close();// 关闭输入流htmlInputStream.close();// 关闭文件输出流IOUtils.closeQuietly(response.getOutputStream());}catch (IOException e) {log.error("", e);}catch (DocumentException e) {log.error("", e);}}/*** 用于中文显示的Provider*/class AsianFontProvider extends XMLWorkerFontProvider {@Overridepublic Font getFont(final String fontname, String encoding, float size, final int style) {try {BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);return new Font(bfChinese, size, style);}catch (Exception e) {}return super.getFont(fontname, encoding, size, style);}}}

这篇关于springboot+itextpdf+thymeleaf+ognl根据静态模版文件实现动态生成pdf文件并导出demo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/831795

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

Java进阶13讲__第12讲_1/2

多线程、线程池 1.  线程概念 1.1  什么是线程 1.2  线程的好处 2.   创建线程的三种方式 注意事项 2.1  继承Thread类 2.1.1 认识  2.1.2  编码实现  package cn.hdc.oop10.Thread;import org.slf4j.Logger;import org.slf4j.LoggerFactory

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

第10章 中断和动态时钟显示

第10章 中断和动态时钟显示 从本章开始,按照书籍的划分,第10章开始就进入保护模式(Protected Mode)部分了,感觉从这里开始难度突然就增加了。 书中介绍了为什么有中断(Interrupt)的设计,中断的几种方式:外部硬件中断、内部中断和软中断。通过中断做了一个会走的时钟和屏幕上输入字符的程序。 我自己理解中断的一些作用: 为了更好的利用处理器的性能。协同快速和慢速设备一起工作