本文整理汇总了Java中com.alibaba.druid.util.StringUtils类的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringUtils类属于com.alibaba.druid.util包,在下文中一共展示了StringUtils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BitPermission
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
public BitPermission(String permissionString) {
String[] array = permissionString.split("\\+");
if(array.length > 1){
resourcesIdentify = array[1];
}
if(StringUtils.isEmpty(resourcesIdentify)){
resourcesIdentify = "*";
}
if(array.length > 2){
permissionBit = Integer.valueOf(array[2]);
}
if(array.length > 3){
instanceId = array[3];
}
if(StringUtils.isEmpty(instanceId)){
instanceId = "*";
}
}
示例2: getIpAddr
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
/**
* 获取IP地址
*
* 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
* 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = null;
try {
ip = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
} catch (Exception e) {
logger.error("IPUtils ERROR ", e);
}
// //使用代理,则获取第一个IP地址
// if(StringUtils.isEmpty(ip) && ip.length() > 15) {
// if(ip.indexOf(",") > 0) {
// ip = ip.substring(0, ip.indexOf(","));
// }
// }
return ip;
}
示例3: getCookieValue
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
/**
* 获取指定名称的Cookie
* @param request 请求
* @param name Cookie名
* @return 指定Cookie
*/
public Cookie getCookieValue(HttpServletRequest request, String name) {
if (request.getCookies() == null) {
return null;
}
for (Cookie cookie : request.getCookies()) {
if (StringUtils.equals(cookie.getName(), name)) {
return cookie;
}
}
return null;
}
示例4: addJob
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
@Transactional
@Override
public boolean addJob(ScheduleJobEntity job) {
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobDetail jobDetail = job.getJobDetail();
if(StringUtils.isEmpty(job.getTriggerGroup()))
{
//使用默认组名称:DEFAULT
job.setTriggerGroup(Scheduler.DEFAULT_GROUP);
}
// 存储job
jobDetail.getJobDataMap().put("scheduleJob", job);
if(!StringUtils.isEmpty(job.getTriggerName())){
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = newTrigger()
.withIdentity(job.getTriggerName(),job.getTriggerGroup())
.startAt(job.getStartDate()) // job开始日期
.endAt(job.getEndDate())// job结束日期
.withSchedule(scheduleBuilder).build();
// 将job添加到quartz的scheduler容器
scheduler.scheduleJob(jobDetail, trigger);
}else
{
scheduler.addJob(jobDetail, true);
}
return Boolean.TRUE;
} catch (SchedulerException e) {
throw new ServiceException(e);
}
}
示例5: getIpAddr
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
/**
* 获取IP地址
* <p>
* 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
* 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = null;
try {
ip = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
} catch (Exception e) {
logger.error("IPUtils ERROR ", e);
}
// //使用代理,则获取第一个IP地址
// if(StringUtils.isEmpty(ip) && ip.length() > 15) {
// if(ip.indexOf(",") > 0) {
// ip = ip.substring(0, ip.indexOf(","));
// }
// }
return ip;
}
示例6: updateTableVerHistoryNotice
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
public void updateTableVerHistoryNotice(Connection conn, long tableId) {
try {
PreparedStatement ps = conn.prepareStatement("select id, ver_id, ver_change_history from t_data_tables where id = ?");
ps.setLong(1, tableId);
ResultSet oldResultSet = ps.executeQuery();
if (oldResultSet.next()) {
/**
* 两个都为空时,更新为新版本
* 只有历史为空时,更新为当前版本+新版本
* 两个都有值,更新为当前历史+新版本
*/
String verChangeHistory = (String) oldResultSet.getObject("ver_change_history");
String verId = (String) oldResultSet.getObject("ver_id");
if (StringUtils.isEmpty(verChangeHistory)) {
if (StringUtils.isEmpty(verId)) {
// 两个都为空,不做处理,连标记也不更新,直接返回
logger.info("Ignore to set ver_change_history while ver_id is null");
return;
} else {
// 历史为空,当前版本不为空,赋值为当前版本
verChangeHistory = verId;
logger.info("Set ver_change_history = ver_id");
}
} else {
if (StringUtils.isEmpty(verId)) {
// 历史不为空,当前版本却为空,不合逻辑,历史不变
logger.warn("An error occurred while updating verChangeHistory. Ver_change_history is not empty, but ver_id is empty. Set ver_change_history unchanged while still show notice");
return;
} else {
// 两个都不为空,直接将当前版本添加进来
verChangeHistory = verChangeHistory + "," + verId;
logger.info("Set ver_change_history += ver_id");
}
}
ps = conn.prepareStatement("update t_data_tables set ver_change_history = ? , ver_change_notice_flg = 1 where id = ?");
ps.setString(1, verChangeHistory);
ps.setLong(2, tableId);
ps.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
logger.error("updateTableVerHistoryNotice failed,error message:{}", e.getMessage());
}
}
示例7: getValueSize
import com.alibaba.druid.util.StringUtils; //导入依赖的package包/类
private static int getValueSize(String value){
return StringUtils.isEmpty(value)?2:value.getBytes(CHARSET).length;
}