• java mix 知识点


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

    前台发送:

    param=1,2  

    后台接收

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

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


    二、toString():

    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("
    ");
            }
        }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属性文件工具类

    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)

     
     
  • 相关阅读:
    dataTables分页实现两个前提
    centos 7 下 nginx 1.10.3 编译安装的方法
    redis 远程连接出错的解决办法
    Yii2事件驱动的运行机制
    Yii2项目高级模版 三个模块在同一个目录下的重定向配置
    PHP处理上传文件信息数组中的文件类型 正确获取
    PHP is_writeable 存在bug , 写一个自定函数 判断文件是否可写
    PHP面试题学习
    解决yii2 禁用layout时AppAsset不加载资源的问题
    如何在 Docker 容器中运行 Kali Linux 2.0
  • 原文地址:https://www.cnblogs.com/niejunlei/p/6956936.html
Copyright © 2020-2023  润新知