• java常用的语句


    //判断一个长的字符串中是否包含某一个短的字符串
    if (str1.indexOf(str2) != -1) {
        return true;//存在
    }else {
        return false;
    }
    /**
     * 消息模板关键字替换
     * @param template  消息内容
     * @param map 替换key-value
     * @return
     */
    public static String replaceTemplate(String template, Map<String, Object> map){
        if(!StringUtils.isBlank(template)){
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                template = template.replaceAll(entry.getKey(), entry.getValue().toString());
            }
        }
        return template;
    }
    /**
     * 生产的随机串
     * @param num 长度
     * @return
     */
    public static String genRadomNbr(Integer num) {
        Random random = new Random();
        String result = "";
        for (int i = 0; i < num; i++) {
            result += random.nextInt(10);
        }
        return result;
    }
    /**
     * 组装返回的json数据
     * @param data
     * @param code
     * @param message
     * @return
     */
    public JSONObject assemblyJson(Object data, String code, String message) {
        JSONObject jsonObject = new JSONObject();// 创建对象
        jsonObject.put("data", data);// 数据不为空的时候设置返回数据
        jsonObject.put("message", message);// 设置状态数据
        jsonObject.put("code", code);
        return jsonObject;
    
    }
    //删除某一字符
    public static String deleteStr(String str, char delChar){
        String delStr = "";
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) != delChar){
                delStr += str.charAt(i);
            }
        }
        return delStr;
    }
  • 相关阅读:
    spring mvc 源码简要分析
    tomcat 开启远程debug
    jdk1.5-jdk1.9的主要区别
    关于elasticsearch 6.x及其插件head安装(单机与集群)5分钟解决
    mysql主从配置(5分钟解决问题)
    内部类总结
    Colored Sticks
    vim 将tab转为空格
    shell编程
    vim -- 查找和替换
  • 原文地址:https://www.cnblogs.com/gjq1126-web/p/11212834.html
Copyright © 2020-2023  润新知