package com.ctrip.framework.apollo.demo; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author maxiaolong * @create 2018-07-17 10:12 **/ public class StreamDemo { public static void main (String[] args) { convert(); } private static void convert () { List<Bean> beanList = Lists.newArrayList(new Bean("k1", "f1", "v1"), new Bean("k1", "f2", "v2"), new Bean("k2", "f2", "v3")); Map<String, Map<String, String>> resultMap = beanList.stream().collect(Collectors.toMap(bean -> bean.getKey(), bean -> { Map map = Maps.newHashMap(); map.put(bean.getField(), bean.getValue()); return map; }, (oldValue, newValue) -> { oldValue.putAll(newValue); return oldValue; })); resultMap.forEach((key, value) -> System.out.println("key: " + key + "; value: " + value)); } static class Bean { private String key; private String field; private String value; public Bean (String key, String field, String value) { this.key = key; this.value = value; this.field = field; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getField() { return field; } public void setField(String field) { this.field = field; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } }
相关推荐
public Map<String, Object> handleAjaxRequest(@RequestParam Map<String, String> params) { // 处理业务逻辑 List<Movie> movies = movieDao.getMovies(params); return Collections.singletonMap("movies", ...
List<Map<String, String>> rules = new ArrayList<>(); // 遍历模型类的字段并处理验证注解 for (Field field : clazz.getDeclaredFields()) { // 处理验证注解,生成验证规则 // ... } // 生成并输出...
List<Student> stuList = new ArrayList<>(); stuList.add(student); stuList.add(student); return stuList; //返回list对象,将会被自动转换为JSON格式 } ``` - **@ResponseBody**:将方法的返回值直接写入...
List<FileItem> fileItems = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(httpRequest); for (FileItem fileItem : fileItems) { if (!fileItem.isFormField()) { String fileName = ...
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); for (Map<String, Object> map : list) { Set<Entry<String, Object>> entries = map.entrySet(); if(entries != null) { Iterator<Entry...
<#list data.array as item> <li>${item.property}</li> </#list> </ul> <!-- 示例HTML截取 --> <div>${truncateHtml(originalHtml, 100)}</div> </body> </html> ``` 这个模板展示了如何展示JSON数据中的...
- Bug fixed: TGMMap -> bug fixed on RemoveLinkedComponent when trying delete an object without being the list created. - Bug fixed: JavaScript => when it had figures of different types together, ...
protected List<Content> getList(Map<String, TemplateModel> params, Environment env) throws TemplateException { Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params); if (ids != null) { //...
public List<User> getUserListByPage(Map<String, Object> params) { return userMapper.getUserListByPage(params); } // 其他服务方法 } ``` 最后,通过创建一个控制器类,我们将这些服务暴露给HTTP请求:...
返回 List<ConfigNode> <br> * ROOT.NODE.CNODE:$value 末结点的TEXT值 返回 String <br> * ROOT.NODE.CNODE:$node 末结点的结点 返回 ConfigNode <br> * ROOT.NODE.CNODE:$properties 末结点的属性表(MAP) 返回 Map...
public List<Girl> getAllGirls() { return girlRepository.findAll(); } public Optional<Girl> getGirlById(Long id) { return girlRepository.findById(id); } public void deleteGirlById(Long id) { ...
Map<String, String> responseMap = new HashMap<>(); responseMap.put("message", "Hello from JSON"); return responseMap; } } ``` 这个例子展示了如何通过不同的视图解析器,根据请求的 URL 返回 JSP、...
AIDL支持基本数据类型和自定义数据类型,以及List、Map等集合类型。 然后,Android Studio或Eclipse会根据`IService.aidl`生成对应的Java接口类`IService.java`,这个类在服务端和客户端都可以使用。服务端需要实现...
<property name="jobClass" value="onlyfun.bb.Quartz.QuartzDemo"></property> <property name="jobDataAsMap"> <map> <entry key="jobData" value-ref="someData"></entry> </map> </property> </bean> ...
Map<String, String> result = new HashMap<>(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser parser = factory.newPullParser(); parser.setInput(is, "UTF-8"); int...
Map<String, Object> variables = new HashMap<>(); variables.put("assignee", "username"); startProcess(businessKey, variables); ``` **5. 流程实例的查询与控制** - **查询流程实例**:使用`TaskService`...
List<String> warnings = new ArrayList<>(); boolean overwrite = true; InputStream in = MyBatisGeneratorMain.class.getResourceAsStream("/generatorConfig.xml"); ConfigurationParser cp = new ...
List<BasicNameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("key1", "value1")); params.add(new BasicNameValuePair("key2", "value2")); httpPost.setEntity(new ...
public Map<String, AuthzHandler> getJdbcAuthz(); } 13.shiro的freemarker标签库 <@shiro.hasPermission name="P_USER"> <li><a href="/admin/user">${i18n.getText("admin.user")}</a></li> ...