Java Code Examples for cn.hutool.core.bean.BeanUtil#mapToBean()
The following examples show how to use
cn.hutool.core.bean.BeanUtil#mapToBean() .
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: MemoryJwtAccessTokenConverter.java From open-capacity-platform with Apache License 2.0 | 6 votes |
public Authentication extractAuthentication(Map<String, ?> map) { if (map.containsKey(USERNAME)) { Object principal = map.get(USERNAME); // Collection<? extends GrantedAuthority> authorities = getAuthorities(map); LoginAppUser loginUser = null; if (principal instanceof Map) { loginUser = BeanUtil.mapToBean((Map) principal, LoginAppUser.class, true); Set<SysRole> roles = new HashSet<>(); for(Iterator<SysRole> it = loginUser.getSysRoles().iterator(); it.hasNext();){ SysRole role = BeanUtil.mapToBean((Map) it.next() , SysRole.class, false); roles.add(role) ; } loginUser.setSysRoles(roles); } return new UsernamePasswordAuthenticationToken(loginUser, "N/A", loginUser.getAuthorities()); } return null; }
Example 2
Source File: MockUrlServiceImpl.java From v-mock with MIT License | 6 votes |
/** * 根据逻辑创建正则查url * * @param requestUrlLogic logic string * @return mockUrl entity */ @SneakyThrows @Override public MockUrl getUrlByRegexp(String requestUrlLogic) { if (StrUtil.isNotBlank(requestUrlLogic)) { // 注册一个带正则的Connection @Cleanup Connection connection = DriverManager.getConnection(dbPath); DataBaseUtils.createRegexpFun(connection); // sql gen // "12,13,14" => ["12","13","14"] String[] afterSplit = requestUrlLogic.split(COMMA); StringJoiner regexpJoiner = new StringJoiner(StrUtil.COMMA); // 将数组遍历 拼接 为正则 Arrays.stream(afterSplit).forEach(item -> // path 直接拼接,数字logic 加上或逻辑拼接 regexpJoiner.add(CommonConst.PATH_PLACEHOLDER.equals(item) ? SQL_REGEXP_PATH : StrUtil.format(SQL_REGEXP_FORMAT, item))); String regexp = "'^".concat(regexpJoiner.toString()).concat("$'"); // 查询 Map<String, Object> mockUrlMap = DataBaseUtils.queryMap(connection, StrUtil.format(SQL_REGEXP, regexp)); if (mockUrlMap != null) { // 转为实体 return BeanUtil.mapToBean(mockUrlMap, MockUrl.class, true); } } return null; }
Example 3
Source File: BaseDbLogService.java From Jpom with MIT License | 6 votes |
/** * 根据主键查询实体 * * @param keyValue 主键值 * @return 数据 */ public T getByKey(String keyValue) { Entity where = new Entity(tableName); where.set(key, keyValue); Db db = Db.use(); db.setWrapper((Character) null); Entity entity; try { entity = db.get(where); } catch (SQLException e) { throw new JpomRuntimeException("数据库异常", e); } if (entity == null) { return null; } CopyOptions copyOptions = new CopyOptions(); copyOptions.setIgnoreError(true); copyOptions.setIgnoreCase(true); return BeanUtil.mapToBean(entity, this.tClass, copyOptions); }
Example 4
Source File: HutoolController.java From mall-learning with Apache License 2.0 | 6 votes |
@ApiOperation("BeanUtil使用:JavaBean的工具类") @GetMapping("/beanUtil") public CommonResult beanUtil() { PmsBrand brand = new PmsBrand(); brand.setId(1L); brand.setName("小米"); brand.setShowStatus(0); //Bean转Map Map<String, Object> map = BeanUtil.beanToMap(brand); LOGGER.info("beanUtil bean to map:{}", map); //Map转Bean PmsBrand mapBrand = BeanUtil.mapToBean(map, PmsBrand.class, false); LOGGER.info("beanUtil map to bean:{}", mapBrand); //Bean属性拷贝 PmsBrand copyBrand = new PmsBrand(); BeanUtil.copyProperties(brand, copyBrand); LOGGER.info("beanUtil copy properties:{}", copyBrand); return CommonResult.success(null, "操作成功"); }
Example 5
Source File: AoomsRestTemplate.java From Aooms with Apache License 2.0 | 6 votes |
public DataResult get(String url, Map<String, Object> params) { DataResult dataResult = new DataResult(); Map map = null; if(useRegistry()){ map = loadBalancedRestTemplate.getForObject(url,Map.class); }else{ String serverUrl = getLocalServerUrl(url); if(logger.isInfoEnabled()){ logger.info("Convert " + url + " -> " + serverUrl); } map = restTemplate.getForObject(serverUrl,Map.class,params); } Map mapStatus = (Map) map.get(AoomsVar.RS_META); DataResultStatus status = BeanUtil.mapToBean(mapStatus,DataResultStatus.class,true); map.put(AoomsVar.RS_META,status); dataResult.setData(map); return dataResult; }
Example 6
Source File: AoomsRestTemplate.java From Aooms with Apache License 2.0 | 6 votes |
public DataResult post(String url, Map<String, Object> params) { DataResult dataResult = new DataResult(); Map map = null; if(useRegistry()){ map = loadBalancedRestTemplate.getForObject(url,Map.class); }else{ String serverUrl = getLocalServerUrl(url); if(logger.isInfoEnabled()){ logger.info("onvert " + url + " -> " + serverUrl); } map = restTemplate.postForObject(serverUrl,params,Map.class); } Map mapStatus = (Map) map.get(AoomsVar.RS_META); DataResultStatus status = BeanUtil.mapToBean(mapStatus,DataResultStatus.class,true); map.put(AoomsVar.RS_META,status); dataResult.setData(map); return dataResult; }
Example 7
Source File: Record.java From Aooms with Apache License 2.0 | 4 votes |
public <T> T toBean(Class<T> beanClass){ return (T)BeanUtil.mapToBean(MapUtil.toCamelCaseMap(this),beanClass,true); //return BeanUtil.fillBeanWithMap(this,beanClass.newInstance(),true,) }
Example 8
Source File: DocumentBrowser.java From book118-downloader with MIT License | 4 votes |
/** * 获取文档的预览地址 * * @param documentId 文档的编号 * @return 预览地址 */ private PdfInfo getPdfInfo(String documentId) { String url = Constants.OPEN_FULL_URL + documentId; String pdfPageUrlStr = HttpUtil.get(url); if (StrUtil.isNotBlank(pdfPageUrlStr)) { pdfPageUrlStr = "https:" + pdfPageUrlStr; } else { StaticLog.error("获取失败!"); return null; } int endOfHost = pdfPageUrlStr.indexOf("?"); String viewHost = pdfPageUrlStr.substring(0, endOfHost); String redirectPage = HttpUtil.get(pdfPageUrlStr); String href = ReUtil.get(Constants.HREF_PATTERN, redirectPage, 1); String fullUrl; if(href != null){ fullUrl = viewHost.substring(0, viewHost.length()-1) + HtmlUtil.unescape(href); }else { fullUrl = pdfPageUrlStr; } String pdfPageHtml = HttpUtil.get(fullUrl); if (pdfPageHtml.contains(Constants.FILE_NOT_EXIST)) { StaticLog.error("获取预览地址失败,请稍后再试!"); return null; } List<String> result = ReUtil.findAllGroup0(Constants.INPUT_PATTERN, pdfPageHtml); Map<String, String> pdfInfoMap = new HashMap<>(6); pdfInfoMap.put("host", viewHost); for (String inputStr : result) { String id = ReUtil.get(Constants.ID_PATTERN, inputStr, 1); String value = ReUtil.get(Constants.VALUE_PATTERN, inputStr, 1); if (StrUtil.isNotBlank(id) && StrUtil.isNotBlank(value)) { id = id.toLowerCase(); try { value = URLEncoder.encode(value, "utf8"); } catch (Exception e) { StaticLog.error("URLEncoder Error", e); } pdfInfoMap.put(id, value); } } return BeanUtil.mapToBean(pdfInfoMap, PdfInfo.class, true); }
Example 9
Source File: DeptFactory.java From Guns with GNU Lesser General Public License v3.0 | 4 votes |
/** * 构造部门树,部门列表用 * * @author fengshuonan * @Date 2019-07-26 17:41 */ public static List<DeptTreeNode> buildTreeNodes(List<Map<String, Object>> originMap) { ArrayList<DeptTreeNode> deptTreeNodes = new ArrayList<>(); for (Map<String, Object> map : originMap) { DeptTreeNode deptTreeNode = BeanUtil.mapToBean(map, DeptTreeNode.class, true); deptTreeNodes.add(deptTreeNode); } DefaultTreeBuildFactory<DeptTreeNode> buildFactory = new DefaultTreeBuildFactory<>(); buildFactory.setRootParentId("0"); return buildFactory.doTreeBuild(deptTreeNodes); }
Example 10
Source File: MenuFactory.java From Guns with GNU Lesser General Public License v3.0 | 4 votes |
/** * 构造菜单树,菜单列表用 * * @author fengshuonan * @Date 2019-07-26 17:41 */ public static List<MenuTreeNode> buildTreeNodes(List<Map<String, Object>> originMap) { ArrayList<MenuTreeNode> menuTreeNodes = new ArrayList<>(); for (Map<String, Object> map : originMap) { MenuTreeNode menuTreeNode = BeanUtil.mapToBean(map, MenuTreeNode.class, true); menuTreeNodes.add(menuTreeNode); } DefaultTreeBuildFactory<MenuTreeNode> treeBuildFactory = new DefaultTreeBuildFactory<>(); treeBuildFactory.setRootParentId("0"); return treeBuildFactory.doTreeBuild(menuTreeNodes); }
Example 11
Source File: DataResult.java From Aooms with Apache License 2.0 | 2 votes |
/** * 获取Bean结果 * @return */ public <T> T getBean(String key,Class<T> beanClass){ return BeanUtil.mapToBean(((Map)results.get(key)),beanClass,true); }
Example 12
Source File: DataResult.java From Aooms with Apache License 2.0 | 2 votes |
/** * 获取PagingRecord结果 * @return */ public RecordGroup getRecordGroup(String key){ return BeanUtil.mapToBean(((Map)results.get(key)),RecordGroup.class,true); }