/**
* Description:判断字段空null <br>
*
* @param s
* @return boolean
*/
public static boolean isNullOrNone(String s) {
if (s == null || "".equals(s.trim())) {
return true;
}
return false;
}
这种操作其实看看 源码中是怎么做的 比如说Stringutils.isBlack
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2ac47f22acfb76cdebf1be9441585ef5.png)
public static String createAndSaveToken(Map<String, String> info) throws Exception {
if (!info.containsKey(CommonConstant.LOGIN_USER_ID)) {
throw new InvalidParameterException("参数中没有包含:" + CommonConstant.LOGIN_USER_ID);
}
String jdi = UUID.randomUUID().toString().replace("-", "");
String jwtSecret = MappingCache.getValue(MappingConstant.KEY_JWT_SECRET);
if (StringUtil.isNullOrNone(jwtSecret)) {
jwtSecret = CommonConstant.DEFAULT_JWT_SECRET;
}
Algorithm algorithm = Algorithm.HMAC256(jwtSecret);
JWTCreator.Builder jwt = JWT.create();
for (String key : info.keySet()) {
if (CommonConstant.LOGIN_USER_ID.equals(key)) {
continue;
}
jwt.withClaim(key, info.get(key));
}
String expireTime = MappingCache.getValue(MappingConstant.KEY_JWT_EXPIRE_TIME);
if (StringUtil.isNullOrNone(expireTime)) {
expireTime = CommonConstant.DEFAULT_JWT_EXPIRE_TIME;
}
JWTCache.setValue(jdi, info.get(CommonConstant.LOGIN_USER_ID), Integer.parseInt(expireTime));
jwt.withIssuer("java110");
jwt.withJWTId(jdi);
return jwt.sign(algorithm);
}
看起来有点乱