前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java mix 知识点

java mix 知识点

作者头像
WindWant
发布2020-09-11 11:01:45
3040
发布2020-09-11 11:01:45
举报
文章被收录于专栏:后端码事后端码事

一、java后台接受web前台传递的数组参数

前台发送:

param=1,2

后台接收

@RequestParam(value = "param") String[] param

@RequestParam(value = "param") List<String> param

二、toString():

代码语言:javascript
复制
public static String reflectionToString(Object o){
    if(o == null) return StringUtils.EMPTY;
    StringBuilder toStr = new StringBuilder();
    if(o instanceof Collection){
        Iterator it = ((Collection) o).iterator();
        while (it.hasNext()){
            toStr.append(reflectionToString(it.next()));
            toStr.append("\n");
        }
    }else if(o instanceof Map){
        Iterator<Map.Entry> mit = ((Map) o).entrySet().iterator();
        while (mit.hasNext()){
            Map.Entry entry = mit.next();
            String kv = entry.getKey() + ": " + reflectionToString(entry.getValue());
            toStr.append(kv);
            toStr.append(" ");
        }
    } else if(o instanceof Object[]){
        for (Object temp: (Object[])o){
            toStr.append(reflectionToString(temp));
        }
    }else if(o instanceof String){
        toStr.append(o);
    } else {
        toStr.append(ToStringBuilder.reflectionToString(o, ToStringStyle.SHORT_PREFIX_STYLE));
    }
    return toStr.toString();
}

三、TreeMap

  • 基于红黑树。
  • 非线程安全。
  • 同步使用:SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...))

四、properties属性文件工具类

代码语言:javascript
复制
package xxx.business.utils;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by windwant on 2016/7/19.
 */
public class ConfigUtils {

    private static final Logger logger = LoggerFactory.getLogger(ConfigUtils.class);

    private static PropertiesConfiguration config = null;

    static {
        try {
            if (config == null) {
                config = new PropertiesConfiguration("config.properties");
                //自动重新加载
                config.setReloadingStrategy(new FileChangedReloadingStrategy());
                //自动保存
                config.setAutoSave(true);
            }
        } catch (ConfigurationException e) {
            logger.error("load config.properties error", e);
            throw new RuntimeException(e);
        }
    }

    private ConfigUtils(){}

    public static String get(String key) {
        if (config != null) {
            String value = config.getString(key);
            return value == null ? "" : value;
        }
        return "";
    }

    public static Integer getInteger(String key) {
        int result = -1;
        if (config != null) {
            try {
                result = Integer.parseInt(config.getString(key));
            } catch (NumberFormatException e) {
                result = -1;
            }
        }
        return result;
    }
}

五、SortedMap基本特性

  • 继承于Map。
  • 提供对key(自然排序顺序或者SortedMap创建时提供的Comparator)的全排序。
  • key必须实现Comparable接口,以便于进行相互比较。
  • 应用于对map的遍历(EntrySet、KeySet、Values)。
  • 对比SortedSet。
  • subMap(fromkey,tokey)、headMap(tokey)、tailMap(fromKey)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-06-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、java后台接受web前台传递的数组参数
  • 二、toString():
  • 三、TreeMap
  • 四、properties属性文件工具类
  • 五、SortedMap基本特性
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档