PDF默认是纵向打印的,通过rotate()来让其改变为横向打印,一般在打印A4 12*21纸以及发票的时候会用横向打印。横向打印时页面会出现行转列以及列转行的情况,因此在设置页面大小的时候一定要宽度设置的宽一些,表格的maxWidth设置在500到600之间就行了,不然会打印的表格就会不是太全或者很少。如果你是纵向打印,那么Rectangle设置页面大小就可以根据实际情况设置了。下面附上代码:

package com.ucfgroup.framework.web.app.company.service.process.pdf.pzPrint;

import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.ucfgroup.framework.utils.DateUtil;
import com.ucfgroup.framework.utils.NumberUtil;
import com.ucfgroup.framework.utils.Rmb;
import com.ucfgroup.framework.web.app.company.entity.CAccvouchAndDetail;
import com.ucfgroup.framework.web.app.company.entity.CUserZt;

public class PDFPrint {
Rectangle pageSize = new Rectangle(1000,730);
Document document = new Document(pageSize);// 建立一个Document对象

private static Font headfont;// 设置字体大小
private static Font keyfont;// 设置字体大小
private static Font textfont;// 设置字体大小
private static Font textfontHead;// 设置字体大小
private static int fm = 0;// 凭证号:记-后面的分母
private static int jcount = 0;// 凭证号:记-后面的分子
@SuppressWarnings("unused")
private static int pageNumber = 0;// 当前页
@SuppressWarnings("unused")
private static int totalPage = 0;// 总页数
private static int totalXhCount = 0;// 总共循环次数
BigDecimal totalJfh = BigDecimal.ZERO;//合计借方和
BigDecimal totalDfh = BigDecimal.ZERO;//合计贷方和
BigDecimal morepageTotalJF=BigDecimal.ZERO;//计算凭证分页时候的总和

static {
BaseFont bfChinese;
try {
bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
headfont = new Font(bfChinese, 19, Font.BOLD);// 设置字体大小
keyfont = new Font(bfChinese, 15, Font.BOLD);// 设置字体大小
textfont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小
textfontHead = new Font(bfChinese, 11, Font.NORMAL);// 设置字体大小
} catch (Exception e) {
e.printStackTrace();
}
}

public PDFPrint(File file,int totalXhCountp,int pageNumberp,int totalPagep,int fmp ,int jcountp) {
totalXhCount = totalXhCountp;
pageNumber = pageNumberp;
fm = fmp;
jcount = jcountp;
document.setPageSize(pageSize.rotate());// 设置页面大小
document.setMargins(60, 50, 30, 10);
try {
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
} catch (Exception e) {
e.printStackTrace();
}

}

int maxWidth = 630;

public PdfPCell createCell(String value, com.itextpdf.text.Font font, int align, int width) {
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setPhrase(new Phrase(value, font));
cell.setPaddingBottom(3);
cell.setPaddingTop(3);
// cell.setFixedHeight(35);
return cell;
}

public PdfPCell createCell(String value, com.itextpdf.text.Font font, int width) {
PdfPCell cell = new PdfPCell();
cell.setPhrase(new Phrase(value, font));
cell.setPaddingBottom(11);
cell.setPaddingTop(11);
// cell.setFixedHeight(35);
return cell;
}

public PdfPCell createCell(String value, com.itextpdf.text.Font font) {
PdfPCell cell = new PdfPCell();
cell.setPhrase(new Phrase(value, font));
cell.setPaddingBottom(11);
cell.setPaddingTop(11);
return cell;
}

public PdfPCell createCell(String value, com.itextpdf.text.Font font, int align, int colspan, boolean boderFlag,
int width) {
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setColspan(colspan);
cell.setPhrase(new Phrase(value, font));
cell.setPadding(3.0f);
if (!boderFlag) {
cell.setBorder(0);
// cell.setPaddingBottom(-50);
}
cell.setFixedHeight(30);
return cell;
}

public PdfPCell createCell(String value, com.itextpdf.text.Font font, int align, int colspan, boolean boderFlag) {
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setColspan(colspan);
cell.setPhrase(new Phrase(value, font));
cell.setPadding(3.0f);
if (!boderFlag) {
cell.setBorder(0);
}
cell.setFixedHeight(30);
if(value.contains("凭证号:记-")){
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
// cell.setPaddingLeft(-5);
}
return cell;
}

public PdfPCell createCell(String value, com.itextpdf.text.Font font, int align, int colspan, boolean boderFlag,
String flag) {
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_LEFT);
cell.setHorizontalAlignment(align);
cell.setColspan(colspan);
cell.setPhrase(new Phrase(value, font));
cell.setPadding(3.0f);
if (!boderFlag) {
cell.setBorder(0);
cell.setPaddingTop(15.0f);
cell.setPaddingBottom(8.0f);
}
cell.setPaddingTop(8);
cell.setPaddingLeft(-2);
if(flag.equals("3")){
cell.setPaddingLeft(-50);
}
if(flag.equals("4")){
cell.setPaddingLeft(-30);
}
return cell;
}

public PdfPTable createTable(int colNumber) {
PdfPTable table = new PdfPTable(colNumber);
try {
table.setTotalWidth(maxWidth);
table.setLockedWidth(true);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setBorder(1);
} catch (Exception e) {
e.printStackTrace();
}
return table;
}

public PdfPTable createTable(float[] widths) {
PdfPTable table = new PdfPTable(widths);
try {
table.setTotalWidth(maxWidth);
table.setLockedWidth(true);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setBorder(1);
} catch (Exception e) {
e.printStackTrace();
}
return table;
}

public PdfPTable createBlankTable() {
PdfPTable table = new PdfPTable(1);
table.getDefaultCell().setBorder(0);
table.addCell(createCell("", keyfont));
table.setSpacingAfter(20.0f);
table.setSpacingBefore(20.0f);
return table;
}

public void generatePDF(HttpServletRequest request, List<CAccvouchAndDetail> list) throws Exception {
int count = 0;
CUserZt zt = (CUserZt) request.getSession().getAttribute("ZTModel");
BigDecimal total = BigDecimal.ZERO;
BigDecimal totalJf = BigDecimal.ZERO;
BigDecimal totalDf = BigDecimal.ZERO;
int caccno = list.get(0).getCaccno();
String caccnoStr = "" + caccno;
if (caccno < 10) {
caccnoStr = "00" + caccno;
}
if (caccno >= 10 && caccno < 100) {
caccnoStr = "0" + caccno;
}
if (fm > 1) {
caccnoStr += "-" + jcount + "/" + fm;
}
PdfPTable table = createTable(4);
table.setWidths(new float[] { 0.22f, 0.42f, 0.18f, 0.18f });// 每个单元格占多宽

PdfPCell createCellp = createCell("yyyy", headfont, Element.ALIGN_CENTER, 1, false, 258);
createCellp.setPaddingLeft(25);

table.addCell(createCell("", headfont, Element.ALIGN_CENTER, 1, false, 202));
table.addCell(createCellp);
table.addCell(createCell("", headfont, Element.ALIGN_CENTER, 1, false, 115));
table.addCell(createCell("附单据数:" + list.get(0).getcFj(), keyfont, Element.ALIGN_RIGHT, 1, false, 115));

table.addCell(createCell(zt.getZtname(), textfontHead, Element.ALIGN_LEFT, 1, false));
table.addCell(createCell("日期:" + DateUtil.dateToString(list.get(0).getCdate(), "yyyy-MM-dd"), textfontHead,
Element.ALIGN_CENTER, 1, false));
// table.addCell(createCell(" ", textfontHead, Element.ALIGN_CENTER, 1, false));
PdfPCell caccnoCell = createCell("凭证号:记-" + caccnoStr, textfontHead, Element.ALIGN_RIGHT, 2, false);
table.addCell(caccnoCell);

PdfPCell createDigestCell = createCell("摘要", keyfont, Element.ALIGN_CENTER, 202);
createDigestCell.setBorderWidthLeft(1.5f);
createDigestCell.setBorderWidthTop(1.5f);
createDigestCell.setBorderWidthBottom(1.5f);
createDigestCell.setFixedHeight(25);

PdfPCell createSubjectCell = createCell("科目名称", keyfont, Element.ALIGN_CENTER, 258);
createSubjectCell.setBorderWidthTop(1.5f);
createSubjectCell.setBorderWidthBottom(1.5f);
createSubjectCell.setFixedHeight(25);

PdfPCell createJfCell = createCell("借方", keyfont, Element.ALIGN_CENTER, 115);
createJfCell.setBorderWidthTop(1.5f);
createJfCell.setBorderWidthBottom(1.5f);
createJfCell.setFixedHeight(25);

PdfPCell createDfCell = createCell("贷方", keyfont, Element.ALIGN_CENTER, 115);
createDfCell.setBorderWidthTop(1.5f);
createDfCell.setBorderWidthBottom(1.5f);
createDfCell.setBorderWidthRight(1.5f);
createDfCell.setFixedHeight(25);

table.addCell(createDigestCell);
table.addCell(createSubjectCell);
table.addCell(createJfCell);
table.addCell(createDfCell);

for (CAccvouchAndDetail cAccvouchAndDetail : list) {
PdfPCell createDigestTextLeftCell = createCell(cAccvouchAndDetail.getCdigest(), textfont, 202);
createDigestTextLeftCell.setBorderWidthLeft(1.5f);

table.addCell(createDigestTextLeftCell);
table.addCell(createCell(cAccvouchAndDetail.getCcodename(), textfont, 258));

PdfPCell createCellj = createCell(judgeMoney(cAccvouchAndDetail.getcJf()), textfont, 115);
createCellj.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellj.setHorizontalAlignment(Element.ALIGN_RIGHT);

PdfPCell createCelld = createCell(judgeMoney(cAccvouchAndDetail.getcDf()), textfont, 115);
createCelld.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCelld.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCelld.setBorderWidthRight(1.5f);

table.addCell(createCellj);
table.addCell(createCelld);
total = total.add(cAccvouchAndDetail.getcJf() == null ? BigDecimal.ZERO : cAccvouchAndDetail.getcJf());
totalJf = totalJf.add(cAccvouchAndDetail.getcJf() == null ? BigDecimal.ZERO : cAccvouchAndDetail.getcJf());//借方合计 ---
totalDf = totalDf.add(cAccvouchAndDetail.getcDf() == null ? BigDecimal.ZERO : cAccvouchAndDetail.getcDf());//贷方合计 ---
count += 1;
}
//借方和贷方和的累加 --
for(;totalXhCount<jcount;){
totalJfh = totalJfh.add(totalJf);
totalDfh = totalDfh.add(totalDf);
break;
}
for (int i = count + 1; i < 6; i++) {
PdfPCell leftBlankCell = createCell(" ", textfont, 202);
leftBlankCell.setBorderWidthLeft(1.5f);
table.addCell(leftBlankCell);
table.addCell(createCell(" ", textfont, 258));
table.addCell(createCell(" ", textfont, 115));
PdfPCell rightBlankCell = createCell(" ", textfont, 115);
rightBlankCell.setBorderWidthRight(1.5f);
table.addCell(rightBlankCell);
}

if (total.compareTo(BigDecimal.ZERO) != 0||
totalJf.compareTo(BigDecimal.ZERO) != 0 ||
totalDf.compareTo(BigDecimal.ZERO) != 0) {
if(jcount > 0 && jcount < fm ){//当凭证为多页
PdfPCell createCelln = createCell("合计:", textfontHead, Element.ALIGN_RIGHT);
createCelln.setColspan(2);
createCelln.setPaddingLeft(4);
createCelln.setPaddingBottom(0);
createCelln.setPaddingTop(0);
createCelln.setFixedHeight(17);
createCelln.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCelln.setBorderWidthLeft(1.5f);
createCelln.setBorderWidthTop(1.5f);
createCelln.setBorderWidthBottom(1.5f);
table.addCell(createCelln);
//添加借方金额到表格
PdfPCell createCellJf = createCell(judgeMoney(totalJf), textfontHead,115);
createCellJf.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellJf.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellJf.setBorderWidthTop(1.5f);
createCellJf.setBorderWidthBottom(1.5f);

table.addCell(createCellJf);

//添加贷方金额到表格
PdfPCell createCellDf = createCell(judgeMoney(totalDf), textfontHead,115);
createCellDf.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellDf.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellDf.setBorderWidthRight(1.5f);
createCellDf.setBorderWidthTop(1.5f);
createCellDf.setBorderWidthBottom(1.5f);
table.addCell(createCellDf);
}
if(jcount == fm ){//当凭证为最后一页时

PdfPCell createCell = createCell("合计:" + Rmb.CmycurD(morepageTotalJF.toString()), textfont,
Element.ALIGN_LEFT);
createCell.setColspan(2);
createCell.setPaddingLeft(4);
createCell.setPaddingBottom(0);
createCell.setPaddingTop(0);
createCell.setFixedHeight(17);
createCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCell.setBorderWidthLeft(1.5f);
createCell.setBorderWidthTop(1.5f);
createCell.setBorderWidthBottom(1.5f);
table.addCell(createCell);

PdfPCell createCellJfs = createCell(judgeMoney(morepageTotalJF), textfont,115);
createCellJfs.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellJfs.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellJfs.setBorderWidthTop(1.5f);
createCellJfs.setBorderWidthBottom(1.5f);

table.addCell(createCellJfs);

PdfPCell createCellDfs = createCell(judgeMoney(morepageTotalJF), textfont,115);
createCellDfs.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellDfs.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellDfs.setBorderWidthRight(1.5f);
createCellDfs.setBorderWidthTop(1.5f);
createCellDfs.setBorderWidthBottom(1.5f);

table.addCell(createCellDfs);

morepageTotalJF=BigDecimal.ZERO;//清除上次的凭证分页金额总和
}
if (jcount == 0 && fm == 1) {//当凭证只有一页
PdfPCell createCell = createCell("合计:" + Rmb.CmycurD(total.toString()), textfont, Element.ALIGN_LEFT);
createCell.setColspan(2);
createCell.setPaddingLeft(4);
createCell.setPaddingBottom(0);
createCell.setPaddingTop(0);
createCell.setFixedHeight(17);
createCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCell.setBorderWidthLeft(1.5f);
createCell.setBorderWidthTop(1.5f);
createCell.setBorderWidthBottom(1.5f);
table.addCell(createCell);

PdfPCell createCellJf = createCell(judgeMoney(totalJf), textfont,115);
createCellJf.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellJf.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellJf.setBorderWidthTop(1.5f);
createCellJf.setBorderWidthBottom(1.5f);

table.addCell(createCellJf);

PdfPCell createCellDf = createCell(judgeMoney(totalDf), textfont,115);
createCellDf.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCellDf.setHorizontalAlignment(Element.ALIGN_RIGHT);
createCellDf.setBorderWidthTop(1.5f);
createCellDf.setBorderWidthBottom(1.5f);
createCellDf.setBorderWidthRight(1.5f);

table.addCell(createCellDf);
}
} else {
PdfPCell createCell = createCell("合计:", textfont, Element.ALIGN_LEFT);
createCell.setColspan(2);
createCell.setPaddingLeft(4);
createCell.setPaddingBottom(0);
createCell.setPaddingTop(0);
createCell.setFixedHeight(17);
createCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
createCell.setBorderWidthTop(1.5f);
createCell.setBorderWidthBottom(1.5f);
createCell.setBorderWidthLeft(1.5f);
table.addCell(createCell);

table.addCell(createCell(" ", keyfont, Element.ALIGN_CENTER,115));
PdfPCell createSumCell = createCell(" ", keyfont, Element.ALIGN_CENTER,115);
table.addCell(createSumCell);
createSumCell.setBorderWidthTop(1.5f);
createSumCell.setBorderWidthBottom(1.5f);
createSumCell.setBorderWidthRight(1.5f);
}

String shrName = zt.getShrName() == null ? "" : zt.getShrName();
String zdrName = zt.getZdrName() == null ? "" : zt.getZdrName();
String zgrName = zt.getZgName() == null ? "" : zt.getZgName();

table.addCell(createCell("xxxx:" + zdrName, textfont, Element.ALIGN_LEFT, 1, false, "1"));
table.addCell(createCell("xxxx:", textfont, Element.ALIGN_LEFT, 1, false, "2"));
table.addCell(createCell("xxxx:"+shrName, textfont, Element.ALIGN_LEFT, 1, false, "3"));
table.addCell(createCell("xxxx:" + zgrName, textfont, Element.ALIGN_LEFT, 1, false, "4"));

document.add(table);

// // 创建Chunk对象,设置下划线的厚度为1
// Chunk strike = new Chunk("");
// strike.setUnderline(1f, 3f);
// document.add(strike);
}

public void printPdf(HttpServletRequest request, Map<String,
List<CAccvouchAndDetail>> map, List<String> aidList,int
fmp,int jcountp)
throws Exception {
fm = fmp;
jcount = jcountp;
int mapSize = aidList.size();
int mapYs = mapSize % 2;
if (mapYs > 0) {
totalPage = mapSize / 2 + 1;
} else {
totalPage = mapSize / 2;
}
for (String aid : aidList) {
List<CAccvouchAndDetail> list = map.get(aid);
Map<Integer, List<CAccvouchAndDetail>> cfListMap = new HashMap<Integer, List<CAccvouchAndDetail>>();
int size = list.size();
int cs = size / 5;
int ys = size % 5;
if (cs > 1) {
if (ys > 0) {
fm = cs + 1;
} else {
fm = cs;
}
}
if (cs == 1 && ys > 0) {
fm = 2;
}
if (size > 5) {
int count = 0;
int jsq = 0;// 计数器
for (CAccvouchAndDetail cAccvouchAndDetail : list) {
morepageTotalJF = morepageTotalJF.add(cAccvouchAndDetail.getcJf());
List<CAccvouchAndDetail> tempList = cfListMap.get(count);
if (null == tempList || jsq == 5) {
jsq = 0;
tempList = new ArrayList<CAccvouchAndDetail>();
tempList.add(cAccvouchAndDetail);
count += 1;
cfListMap.put(count, tempList);
jsq += 1;
} else {
tempList.add(cAccvouchAndDetail);
jsq += 1;
}
}
jcount = 0;
for (int i = 0; i < fm; i++) {
List<CAccvouchAndDetail> cfList = cfListMap.get(i + 1);
jcount += 1;
generatePDF(request, cfList);
document.newPage();
totalXhCount += 1;
}
} else {
fm = 1;
jcount = 0;
generatePDF(request, list);
document.newPage();
totalXhCount += 1;
}

}
document.close();
}

public static String leftPad(String str, int i) {
int addSpaceNo = i - str.length();
String space = "";
for (int k = 0; k < addSpaceNo; k++) {
space = " " + space;
}
;
String result = space + str;
return result;
}

private String judgeMoney(BigDecimal bd) {
String temp = "";
if(bd != null && bd.compareTo(BigDecimal.ZERO) != 0){
temp = NumberUtil.msStrAddComma(NumberUtil.msBigDecimalFormat(bd));
}
return temp;
}
}

java的PDF纵横向打印的更多相关文章

  1. JAVA导出pdf实例

    一.直接导出成PDF   Java代码 1. import java.io.FileNotFoundException; 2. import java.io.FileOutputStream; 3.  ...

  2. itextpdf JAVA 输出PDF文档

    使用JAVA生成PDF的时候,还是有些注意事项需要处理的. 第一.中文问题,默认的itext是不支持中文的,想要支持,需要做些处理. 1.直接引用操作系统的中文字体库支持,由于此方案限制性强,又绑定了 ...

  3. Java IO(Properties/对象序列化/打印流/commons-io)

    Java IO(Properties/对象序列化/打印流/commons-io) Properties Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载. ...

  4. 转 Java操作PDF之iText详细入门

    转 Java操作PDF之iText详细入门 2016年08月08日 11:06:00 阅读数:19490 iText是著名的开放项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成 ...

  5. java根据pdf模版动态生成pdf

    java根据pdf模版动态生成pdf package com.utils; import java.io.ByteArrayOutputStream; import java.io.File; imp ...

  6. java里如何实现循环打印出字符或字符数组里的内容

    不多说,直接上干货! java里如何实现循环打印出字符里的内容 没写,暂时不会 java里如何实现循环打印出字符数组里的内容 public class test { public static voi ...

  7. java里如何实现循环打印出字符串或字符串数组里的内容

    不多说,直接上干货! java里如何实现循环打印出字符串里的内容 思路:可以先将字符串转换成字符串数组. public class test { public static void main(Str ...

  8. 个人永久性免费-Excel催化剂功能第50波-批量打印、导出PDF、双面打印功能

    在倡导无纸化办公的今天,是否打印是一个碍眼的功能呢,某些时候的确是,但对于数据的留存,在现在鼓吹区块链技术的今天,仍然不失它的核心价值,数据报表.单据打印出来留存,仍然是一种不可或缺的数据存档和防篡改 ...

  9. java生成二维码打印到浏览器

    java生成二维码打印到浏览器   解决方法: pom.xml的依赖两个jar包: <!-- https://mvnrepository.com/artifact/com.google.zxin ...

随机推荐

  1. iOS 基础

    layoutSubviews: layoutSubviews是对sbuviews的重新布局,比如,我们想更新子视图的位置,可以通过调用layoutSubviews方法(不能直接调用) layoutSu ...

  2. 详解 Facebook 田渊栋 NIPS2017 论文:深度强化学习研究的 ELF 平台

    这周,机器学习顶级会议 NIPS 2017 的论文评审结果已经通知到各位论文作者了,许多作者都马上发 Facebook/Twitter/Blog/ 朋友圈分享了论文被收录的喜讯.大家的熟人 Faceb ...

  3. 如何对hashmap按value值排序

    http://bbs.csdn.net/topics/90321713 这个帖子中没有我想要的答案,treemap是根据key排序的,想以value排序,那么可以key,value互换一下,不过这样的 ...

  4. mysql sleep连接过多解决办法

    睡眠连接过多,会对mysql服务器造成什么影响? 严重消耗mysql服务器资源(主要是cpu, 内存),并可能导致mysql崩溃. 造成睡眠连接过多的原因? 1. 使用了太多持久连接(个人觉得,在高并 ...

  5. UVA-712-满二叉树

    一个策略树(S-tree)是一组变量Xn={x1,x2...xn}的表现形式,它代表一个布尔函数f:{0,1}n->{0,1},策略树每条路径从根结点开始由n+1个结点组成,策略树的每一个结点都 ...

  6. 如何从编程的本质理解JVM内存模型

    如何从编程的本质理解JVM内存模型 一般聊JVM内存模型都是把图截出来,然后对着图,解释上面堆.栈之类的概念.这篇将分享下,如何从编程的本质上理解,JVM内存模型是什么样子,为什么是这个样子,不再死记 ...

  7. Code First use dotConnect for MySQL

    http://www.dotblogs.com.tw/yc421206/archive/2014/03/24/144507.aspx dotConnect for MySQL 是一家強大的 3rd C ...

  8. leetcode268

    public class Solution { public int MissingNumber(int[] nums) { var list = nums.OrderBy(x => x).To ...

  9. json和java bean的相互转换(使用fastjson)

    <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifac ...

  10. J2SE 8的输入输出--Path/Paths File/Files; FileSystems 类的用法

    Path的简单用法 //1. Path 正常用法 Path path = Paths.get("src/main/resource/zip"); logger.debug(path ...