11.excel与word与token组件
1.excel读写
一般项目中excel导入导出功能.导入excel即读取excel,导出excel即生成excel。
apache的poi组件进行excel操作。
-
添加poi环境
-
读excel
XSSFWorkbook book = new XSSFWorkbook(InputStream in)
Sheet sheet = book.getSheet()
写excel
XSSFWorkbook book = new XSSFWorkbook()
Sheet sheet = book.createSheet()
...向sheet中写数据
book.write(OutputStream
2.word生成
生成一个word文件,政务系统,财务系统。(生成合同,生成政府电子文档)
使用freeMarker模板引擎来生成word文件
1.添加freeMarker的jar包
2.创建word模板
Configuration c=new Configuration()
3.token工具
jar包
jjwt-jackson-0.11.2.jar
jjwt-impl-0.11.2.jar
jjwt-api-0.11.2.jar
jackson-databind-2.9.6.jar
jackson-core-2.9.6.jar
jackson-annotations-2.9.6.jar
代码
package com.javasm.jwt;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.io.Encoders;
import io.jsonwebtoken.security.Keys;
import java.security.Key;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class JwtUtil {
private static String keyStr = "Y35yyCm16xZ7TwcNIAZRjDtiNc/loypN0GN331O/3r4=";
private static Long expirMills = 10 * 1000L;
public static void main(String[] args) throws InterruptedException {
String t = generate("1111111");
System.out.println(t);
Claims claims = parse(t);
String uphone = getUphone(claims);
Date expiation = getExpiation(claims);
System.out.println(uphone+"--"+expiation);
Thread.sleep(11*1000);
Claims claims2 = parse(t);
System.out.println(claims2);
}
public static void generateKey() {
Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
String secretString = Encoders.BASE64.encode(key.getEncoded());
System.out.println(secretString);
}
public static String generate(String uphone) {
Key key = Keys.hmacShaKeyFor(Decoders.BASE64.decode(keyStr));
Date current = new Date();
Date expirDate = new Date(current.getTime() + expirMills);
Map<String, String> claims = new HashMap<>();
claims.put("p", uphone);
String jws = Jwts.builder().setClaims(claims).setIssuedAt(current).setExpiration(expirDate).signWith(key).compact();
return jws;
}
public static Claims parse(String token) {
Jws<Claims> jws = Jwts.parserBuilder()
.setSigningKey(keyStr).build().parseClaimsJws(token);
return jws.getBody();
}
public static String getUphone(Claims claim){
return (String)claim.get("p");
}
public static Date getIssuedAt(Claims claim){
return claim.getIssuedAt();
}
public static Date getExpiation(Claims claim){
return claim.getExpiration();
}
}