Skip to content

Instantly share code, notes, and snippets.

View a.java
public static String decrypt(String encrypted) {
String KEY = ")O[NB]6,YF}+efcaj{+oESb9d8>Z'e9M";
String IV = "L+\\~f4,Ir)b$=pkf";
try {
IvParameterSpec iv = new IvParameterSpec(IV.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
@diaolizhi
diaolizhi / a.java
Last active Apr 10, 2019
Map 遍历时删除元素
View a.java
// 创建 Map
Map<String, String> map = new HashMap<>();
// 添加元素
map.put("1", "张三");
map.put("2", "李四");
map.put("3", "王五");
// 获取存放键值的集合
// Map 并没有 iterator 方法,所以不能 map.iterator() 获取迭代器
@diaolizhi
diaolizhi / ReloadSystem.java
Created Jan 13, 2019
Java 执行 shell 脚本
View ReloadSystem.java
public class ReloadSystem {
public static void reloadSystem() {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", "bash ~/tieba-demo/Tieba/reload.sh");
try {
Process process = processBuilder.start();
@diaolizhi
diaolizhi / reload.sh
Last active Jan 13, 2019
Linux git 同步 maven 编译 java -jar 执行
View reload.sh
# 项目名
PRONAME="demo"
#echo $PRONAME
# 项目所在路径
PROPATH='/root/tieba-demo/Tieba/'
nohup git pull origin master >/dev/null 2>&1
#git pull origin master
cd $PROPATH
@diaolizhi
diaolizhi / insert.java
Last active Jan 7, 2019
mysql 插入数据时如果存在主键则只更新
View insert.java
@Insert("INSERT INTO t_email_link VALUES (#{email}, #{link}, DATE_ADD(CURDATE(), INTERVAL 2 DAY))" +
"ON DUPLICATE KEY UPDATE link=#{link}, exp=DATE_ADD(CURDATE(), INTERVAL 2 DAY)")
void saveEmailAndChangePasswordLink(@Param("email") String email, @Param("link") String link);
//重点是 ON DUPLICATE KEY UPDATE
@diaolizhi
diaolizhi / insert.java
Created Jan 7, 2019
mysql 插入数据时如果存在主键则跳过
View insert.java
@Insert("INSERT IGNORE INTO t_user " +
"(email, password, salt, is_active) " +
"VALUES (#{email}, #{password}, #{salt}, 1)")
int addUser(TUser user);
//重点是 IGNORE
View RandomString.java
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
public class RandomString {
/**
* Generate a random string.
*/
View Bootstrap 点击时自动隐藏导航栏
<nav class="navbar navbar-light navbar-expand-md navigation-clean-button">
<div data-toggle="collapse" data-target=".navbar-collapse.show" class="container"><router-link class="navbar-brand" to="/">首页</router-link><button class="navbar-toggler" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse"
id="navcol-1">
<ul class="nav navbar-nav mr-auto">
<li class="nav-item" role="presentation"><router-link class="nav-link" to="/see-other-forum-list">查贴吧</router-link></li>
<li class="nav-item" role="presentation"><a class="nav-link" href="#">Second Item</a></li>
<li class="dropdown"><a class="dropdown-toggle nav-link dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#">Dropdown</a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" role="presentation" href=
@diaolizhi
diaolizhi / JsonData.java
Created Nov 19, 2018
Spring Boot JsonData 封装
View JsonData.java
import java.io.Serializable;
/**
* 功能描述:工具类
*
* <p> 创建时间:May 14, 2018 7:58:06 PM </p>
*/
public class JsonData implements Serializable {
/**
@diaolizhi
diaolizhi / 加解密工具类.java
Last active Nov 18, 2018
Java JWT 加密解密
View 加解密工具类.java
package com.diaolizhi.mybatisdemo.utils;
import com.diaolizhi.mybatisdemo.domain.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
You can’t perform that action at this time.