集合初始化指定长度

master
星期八 5 years ago
parent f36b0d8816
commit bb54a2b15e
  1. 3
      src/main/java/com/lq/code/util/sql/SqlUtil.java
  2. 2
      src/main/java/com/lq/wechat/util/MessageUtil.java

@ -73,9 +73,10 @@ public class SqlUtil {
* @return * @return
*/ */
public static Map<String,String> getAttributeAndColumn(Class entityClazz){ public static Map<String,String> getAttributeAndColumn(Class entityClazz){
Map<String,String> map=new HashMap<>();
List<Field> fieldsList=BeanUtil.getAllField(entityClazz); List<Field> fieldsList=BeanUtil.getAllField(entityClazz);
Iterator iterator = fieldsList.iterator(); Iterator iterator = fieldsList.iterator();
Map<String,String> map=new HashMap<>(fieldsList.size());
while (iterator.hasNext()){ while (iterator.hasNext()){
Field field = (Field) iterator.next(); Field field = (Field) iterator.next();
map.put(field.getName(),caseToHump(field.getName())); map.put(field.getName(),caseToHump(field.getName()));

@ -30,13 +30,13 @@ public class MessageUtil {
* @throws DocumentException * @throws DocumentException
*/ */
public static Map<String, String> xmlToMap(HttpServletRequest req) throws IOException, DocumentException{ public static Map<String, String> xmlToMap(HttpServletRequest req) throws IOException, DocumentException{
Map<String, String> map=new HashMap<>();
SAXReader reader=new SAXReader(); SAXReader reader=new SAXReader();
InputStream ins=req.getInputStream(); InputStream ins=req.getInputStream();
String resultString=IoUtil.convertStreamToString(ins); String resultString=IoUtil.convertStreamToString(ins);
Document doc=DocumentHelper.parseText(resultString); Document doc=DocumentHelper.parseText(resultString);
Element root=doc.getRootElement(); Element root=doc.getRootElement();
List<Element> list=root.elements(); List<Element> list=root.elements();
Map<String, String> map=new HashMap<>(list.size());
for(Element e:list){ for(Element e:list){
map.put(e.getName(), e.getText()); map.put(e.getName(), e.getText());
} }

Loading…
Cancel
Save