com.ruoyi.common.utils.StringUtils Java Examples
The following examples show how to use
com.ruoyi.common.utils.StringUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Convert.java From supplierShop with MIT License | 6 votes |
/** * 转换为Long数组<br> * * @param split 分隔符 * @param str 被转换的值 * @return 结果 */ public static Long[] toLongArray(String split, String str) { if (StringUtils.isEmpty(str)) { return new Long[] {}; } String[] arr = str.split(split); final Long[] longs = new Long[arr.length]; for (int i = 0; i < arr.length; i++) { final Long v = toLong(arr[i], null); longs[i] = v; } return longs; }
Example #2
Source File: DataSourceAspect.java From supplierShop with MIT License | 6 votes |
/** * 获取需要切换的数据源 */ public DataSource getDataSource(ProceedingJoinPoint point) { MethodSignature signature = (MethodSignature) point.getSignature(); Class<? extends Object> targetClass = point.getTarget().getClass(); DataSource targetDataSource = targetClass.getAnnotation(DataSource.class); if (StringUtils.isNotNull(targetDataSource)) { return targetDataSource; } else { Method method = signature.getMethod(); DataSource dataSource = method.getAnnotation(DataSource.class); return dataSource; } }
Example #3
Source File: GenTableServiceImpl.java From RuoYi-Vue with MIT License | 6 votes |
/** * 修改保存参数校验 * * @param genTable 业务信息 */ @Override public void validateEdit(GenTable genTable) { if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { String options = JSON.toJSONString(genTable.getParams()); JSONObject paramsObj = JSONObject.parseObject(options); if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { throw new CustomException("树编码字段不能为空"); } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { throw new CustomException("树父编码字段不能为空"); } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { throw new CustomException("树名称字段不能为空"); } } }
Example #4
Source File: SysUserServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 查询用户所属岗位组 * * @param userId 用户ID * @return 结果 */ @Override public String selectUserPostGroup(Long userId) { List<SysPost> list = postMapper.selectPostsByUserId(userId); StringBuffer idsStr = new StringBuffer(); for (SysPost post : list) { idsStr.append(post.getPostName()).append(","); } if (StringUtils.isNotEmpty(idsStr.toString())) { return idsStr.substring(0, idsStr.length() - 1); } return idsStr.toString(); }
Example #5
Source File: SysProfileController.java From supplierShop with MIT License | 6 votes |
@Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(String oldPassword, String newPassword) { SysUser user = ShiroUtils.getSysUser(); if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt())); if (userService.resetUserPwd(user) > 0) { ShiroUtils.setSysUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } else { return error("修改密码失败,旧密码错误"); } }
Example #6
Source File: Convert.java From ruoyiplus with MIT License | 6 votes |
/** * 转换为Integer数组<br> * * @param split 分隔符 * @param split 被转换的值 * @return 结果 */ public static Integer[] toIntArray(String split, String str) { if (StringUtils.isEmpty(str)) { return new Integer[] {}; } String[] arr = str.split(split); final Integer[] ints = new Integer[arr.length]; for (int i = 0; i < arr.length; i++) { final Integer v = toInt(arr[i], 0); ints[i] = v; } return ints; }
Example #7
Source File: TestController.java From supplierShop with MIT License | 6 votes |
@ApiOperation("更新用户") @ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity") @PutMapping("/update") public AjaxResult update(UserEntity user) { if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) { return error("用户ID不能为空"); } if (users.isEmpty() || !users.containsKey(user.getUserId())) { return error("用户不存在"); } users.remove(user.getUserId()); return AjaxResult.success(users.put(user.getUserId(), user)); }
Example #8
Source File: SysDeptServiceImpl.java From ruoyiplus with MIT License | 6 votes |
/** * 修改保存部门信息 * * @param dept 部门信息 * @return 结果 */ @Override public int updateDept(SysDept dept) { SysDept info = deptMapper.selectDeptById(dept.getParentId()); if (StringUtils.isNotNull(info)) { String ancestors = info.getAncestors() + "," + info.getDeptId(); dept.setAncestors(ancestors); updateDeptChildren(dept.getDeptId(), ancestors); } int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) { // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatus(dept); } return result; }
Example #9
Source File: XssFilter.java From ruoyiplus with MIT License | 6 votes |
@Override public void init(FilterConfig filterConfig) throws ServletException { String tempExcludes = filterConfig.getInitParameter("excludes"); String tempEnabled = filterConfig.getInitParameter("enabled"); if (StringUtils.isNotEmpty(tempExcludes)) { String[] url = tempExcludes.split(","); for (int i = 0; url != null && i < url.length; i++) { excludes.add(url[i]); } } if (StringUtils.isNotEmpty(tempEnabled)) { enabled = Boolean.valueOf(tempEnabled); } }
Example #10
Source File: SysShiroService.java From supplierShop with MIT License | 6 votes |
public Session createSession(SysUserOnline userOnline) { OnlineSession onlineSession = new OnlineSession(); if (StringUtils.isNotNull(userOnline)) { onlineSession.setId(userOnline.getSessionId()); onlineSession.setHost(userOnline.getIpaddr()); onlineSession.setBrowser(userOnline.getBrowser()); onlineSession.setOs(userOnline.getOs()); onlineSession.setDeptName(userOnline.getDeptName()); onlineSession.setLoginName(userOnline.getLoginName()); onlineSession.setStartTimestamp(userOnline.getStartTimestamp()); onlineSession.setLastAccessTime(userOnline.getLastAccessTime()); onlineSession.setTimeout(userOnline.getExpireTime()); } return onlineSession; }
Example #11
Source File: DataSourceAspect.java From ruoyiplus with MIT License | 6 votes |
@Around("dsPointCut()") public Object around(ProceedingJoinPoint point) throws Throwable { MethodSignature signature = (MethodSignature) point.getSignature(); Method method = signature.getMethod(); DataSource dataSource = method.getAnnotation(DataSource.class); if (StringUtils.isNotNull(dataSource)) { DynamicDataSourceContextHolder.setDateSoureType(dataSource.value().name()); } try { return point.proceed(); } finally { // 销毁数据源 在执行方法之后 DynamicDataSourceContextHolder.clearDateSoureType(); } }
Example #12
Source File: RepeatableFilter.java From RuoYi-Vue with MIT License | 6 votes |
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ServletRequest requestWrapper = null; if (request instanceof HttpServletRequest && StringUtils.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE)) { requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); } if (null == requestWrapper) { chain.doFilter(request, response); } else { chain.doFilter(requestWrapper, response); } }
Example #13
Source File: FilterConfig.java From supplierShop with MIT License | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Bean public FilterRegistrationBean xssFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setDispatcherTypes(DispatcherType.REQUEST); registration.setFilter(new XssFilter()); registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); registration.setName("xssFilter"); registration.setOrder(Integer.MAX_VALUE); Map<String, String> initParameters = new HashMap<String, String>(); initParameters.put("excludes", excludes); initParameters.put("enabled", enabled); registration.setInitParameters(initParameters); return registration; }
Example #14
Source File: GenTableColumn.java From RuoYi-Vue with MIT License | 6 votes |
public String readConverterExp() { String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); StringBuffer sb = new StringBuffer(); if (StringUtils.isNotEmpty(remarks)) { for (String value : remarks.split(" ")) { if (StringUtils.isNotEmpty(value)) { Object startStr = value.subSequence(0, 1); String endStr = value.substring(1); sb.append("").append(startStr).append("=").append(endStr).append(","); } } return sb.deleteCharAt(sb.length() - 1).toString(); } else { return this.columnComment; } }
Example #15
Source File: SysMenuController.java From RuoYi-Vue with MIT License | 6 votes |
/** * 新增菜单 */ @PreAuthorize("@ss.hasPermi('system:menu:add')") @Log(title = "菜单管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody SysMenu menu) { if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) { return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) { return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); } menu.setCreateBy(SecurityUtils.getUsername()); return toAjax(menuService.insertMenu(menu)); }
Example #16
Source File: EscapeUtil.java From RuoYi-Vue with MIT License | 6 votes |
/** * Escape编码 * * @param text 被编码的文本 * @return 编码后的字符 */ private static String encode(String text) { int len; if ((text == null) || ((len = text.length()) == 0)) { return StringUtils.EMPTY; } StringBuilder buffer = new StringBuilder(len + (len >> 2)); char c; for (int i = 0; i < len; i++) { c = text.charAt(i); if (c < 64) { buffer.append(TEXT[c]); } else { buffer.append(c); } } return buffer.toString(); }
Example #17
Source File: SysDeptServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 根据角色ID查询部门(数据权限) * * @param role 角色对象 * @return 部门列表(数据权限) */ @Override public List<Ztree> roleDeptTreeData(SysRole role) { Long roleId = role.getRoleId(); List<Ztree> ztrees = new ArrayList<Ztree>(); List<SysDept> deptList = selectDeptList(new SysDept()); if (StringUtils.isNotNull(roleId)) { List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId); ztrees = initZtree(deptList, roleDeptList); } else { ztrees = initZtree(deptList); } return ztrees; }
Example #18
Source File: Convert.java From supplierShop with MIT License | 5 votes |
/** * 转换为Short<br> * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br> * 转换失败不会报错 * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 */ public static Short toShort(Object value, Short defaultValue) { if (value == null) { return defaultValue; } if (value instanceof Short) { return (Short) value; } if (value instanceof Number) { return ((Number) value).shortValue(); } final String valueStr = toStr(value, null); if (StringUtils.isEmpty(valueStr)) { return defaultValue; } try { return Short.parseShort(valueStr.trim()); } catch (Exception e) { return defaultValue; } }
Example #19
Source File: GenUtils.java From RuoYi-Vue with MIT License | 5 votes |
/** * 获取数据库类型字段 * * @param columnType 列类型 * @return 截取后的列类型 */ public static String getDbType(String columnType) { if (StringUtils.indexOf(columnType, "(") > 0) { return StringUtils.substringBefore(columnType, "("); } else { return columnType; } }
Example #20
Source File: SysMenuServiceImpl.java From RuoYi-Vue with MIT License | 5 votes |
/** * 构建前端路由所需要的菜单 * * @param menus 菜单列表 * @return 路由列表 */ @Override public List<RouterVo> buildMenus(List<SysMenu> menus) { List<RouterVo> routers = new LinkedList<RouterVo>(); for (SysMenu menu : menus) { RouterVo router = new RouterVo(); router.setHidden("1".equals(menu.getVisible())); router.setName(getRouteName(menu)); router.setPath(getRouterPath(menu)); router.setComponent(getComponent(menu)); router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); List<SysMenu> cMenus = menu.getChildren(); if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { router.setAlwaysShow(true); router.setRedirect("noRedirect"); router.setChildren(buildMenus(cMenus)); } else if (isMeunFrame(menu)) { List<RouterVo> childrenList = new ArrayList<RouterVo>(); RouterVo children = new RouterVo(); children.setPath(menu.getPath()); children.setComponent(menu.getComponent()); children.setName(StringUtils.capitalize(menu.getPath())); children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); childrenList.add(children); router.setChildren(childrenList); } routers.add(router); } return routers; }
Example #21
Source File: Convert.java From supplierShop with MIT License | 5 votes |
/** * 转换为字符<br> * 如果给定的值为null,或者转换失败,返回默认值<br> * 转换失败不会报错 * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 */ public static Character toChar(Object value, Character defaultValue) { if (null == value) { return defaultValue; } if (value instanceof Character) { return (Character) value; } final String valueStr = toStr(value, null); return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); }
Example #22
Source File: BaseController.java From supplierShop with MIT License | 5 votes |
/** * 设置请求分页数据 */ protected void startPage() { PageDomain pageDomain = TableSupport.buildPageRequest(); Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) { String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); PageHelper.startPage(pageNum, pageSize, orderBy); } }
Example #23
Source File: SysUserServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 校验email是否唯一 * * @param user 用户信息 * @return */ @Override public String checkEmailUnique(SysUser user) { Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); SysUser info = userMapper.checkEmailUnique(user.getEmail()); if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { return UserConstants.USER_EMAIL_NOT_UNIQUE; } return UserConstants.USER_EMAIL_UNIQUE; }
Example #24
Source File: Convert.java From supplierShop with MIT License | 5 votes |
/** * 转换为boolean<br> * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br> * 转换失败不会报错 * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 */ public static Boolean toBool(Object value, Boolean defaultValue) { if (value == null) { return defaultValue; } if (value instanceof Boolean) { return (Boolean) value; } String valueStr = toStr(value, null); if (StringUtils.isEmpty(valueStr)) { return defaultValue; } valueStr = valueStr.trim().toLowerCase(); switch (valueStr) { case "true": return true; case "false": return false; case "yes": return true; case "ok": return true; case "no": return false; case "1": return true; case "0": return false; default: return defaultValue; } }
Example #25
Source File: SysPostServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 校验岗位名称是否唯一 * * @param post 岗位信息 * @return 结果 */ @Override public String checkPostNameUnique(SysPost post) { Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); SysPost info = postMapper.checkPostNameUnique(post.getPostName()); if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { return UserConstants.POST_NAME_NOT_UNIQUE; } return UserConstants.POST_NAME_UNIQUE; }
Example #26
Source File: Convert.java From ruoyiplus with MIT License | 5 votes |
/** * 转换为Enum对象<br> * 如果给定的值为空,或者转换失败,返回默认值<br> * * @param clazz Enum的Class * @param value 值 * @param defaultValue 默认值 * @return Enum */ public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) { if (value == null) { return defaultValue; } if (clazz.isAssignableFrom(value.getClass())) { @SuppressWarnings("unchecked") E myE = (E) value; return myE; } final String valueStr = toStr(value, null); if (StringUtils.isEmpty(valueStr)) { return defaultValue; } try { return Enum.valueOf(clazz, valueStr); } catch (Exception e) { return defaultValue; } }
Example #27
Source File: Convert.java From RuoYi-Vue with MIT License | 5 votes |
/** * 转换为BigInteger<br> * 如果给定的值为空,或者转换失败,返回默认值<br> * 转换失败不会报错 * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 */ public static BigInteger toBigInteger(Object value, BigInteger defaultValue) { if (value == null) { return defaultValue; } if (value instanceof BigInteger) { return (BigInteger) value; } if (value instanceof Long) { return BigInteger.valueOf((Long) value); } final String valueStr = toStr(value, null); if (StringUtils.isEmpty(valueStr)) { return defaultValue; } try { return new BigInteger(valueStr); } catch (Exception e) { return defaultValue; } }
Example #28
Source File: SysPostServiceImpl.java From RuoYi-Vue with MIT License | 5 votes |
/** * 校验岗位编码是否唯一 * * @param post 岗位信息 * @return 结果 */ @Override public String checkPostCodeUnique(SysPost post) { Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; }
Example #29
Source File: ScheduleRunnable.java From ruoyiplus with MIT License | 5 votes |
public ScheduleRunnable(String beanName, String methodName, String params) throws NoSuchMethodException, SecurityException { this.target = SpringUtils.getBean(beanName); this.params = params; if (StringUtils.isNotEmpty(params)) { this.method = target.getClass().getDeclaredMethod(methodName, String.class); } else { this.method = target.getClass().getDeclaredMethod(methodName); } }
Example #30
Source File: SysUserOnlineServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 通过会话序号删除信息 * * @param sessionId 会话ID * @return 在线用户信息 */ @Override public void deleteOnlineById(String sessionId) { SysUserOnline userOnline = selectOnlineById(sessionId); if (StringUtils.isNotNull(userOnline)) { userOnlineDao.deleteOnlineById(sessionId); } }