zoukankan      html  css  js  c++  java
  • java常用 api

    java -cp .:/app/jenkins/ojdbc6-11.2.0.1.0.jar  QueryInterTestImpl

    onclick="add_win.after(initValues)()" //先执行add_win方法,再执行initValues方法
    onclick="setForbidTime.after(add_params)('gomewalletbankinfo/save.dhtml','save')"

    mysql int11 位转日期 需要 乘以1000

      

    Files.readLines(file, Charset.forName("utf-8"), new LineProcessor() {
     @Override
     public boolean processLine(String line) throws IOException {
     String[] messages = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, ",");
     String[] socketLogicIds = StringUtils.splitByWholeSeparatorPreserveAllTokens(finalLogicId, ",");
     StringBuffer socketLogicIdValue = new StringBuffer();
     for(int i=0;i<socketLogicIds.length;i++){
     int index = Integer.parseInt(socketLogicIds[i]);
     socketLogicIdValue.append(messages[index].equalsIgnoreCase("null")?"":messages[index]);
     }
     
     StringBuffer socketLacCiIdKey = new StringBuffer();
     int socketLacCiIdIndex = Integer.parseInt(finalLacCiId);
     socketLacCiIdKey.append(messages[socketLacCiIdIndex]);
     laciCacheDara.put(socketLacCiIdKey.toString(), socketLogicIdValue.toString());
     return true;
     }

    2  apache stringUtils   String[] messages = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, ",");  StringUtils.isNotBlank(str)

     guava strings  Strings.isNullOrEmpty(processStr)

     Introspector.decapitalize :  Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".

    CollectionUtils.isEmpty(list); list为NULL也可以用

    3 class.cast(object)

    4  xStream转换xml 和 json

       XStream xstream = new XStream(new DomDriver());
       xstream.alias("file", FileConfig.class);

       http://www.cnblogs.com/hoojo/archive/2011/04/22/2025197.html

    5 URL confFileUrl = getClass().getResource(fileName);

    6 apache dateUtil  

         Date date = new Date();
             String aString = DateFormatUtils.format(date, "yyyy-MM-dd ");
             Date  ddDate =DateUtils.addDays(date, -10);

        String execDate ="20141210";
    Date date = DateUtils.parseDate(execDate, new String[]{"yyyyMMdd"});
    System.out.println(date);
    String startDateStr = DateFormatUtils.format(date, "yyyy-MM-01 00:00:00");
    System.out.println(startDateStr);
    DateUtils.addDays(date, 2);

     7  web工程out输出 

    	private static final void out(String string, HttpServletResponse response) {
    		PrintWriter writer = null;
    		try {
    			response.setContentType("application/json; charset=UTF-8");
    			response.setCharacterEncoding("UTF-8");
    			response.setHeader("progma", "no-cache");
    			response.setHeader("Access-Control-Allow-Origin", "*");
    			response.setHeader("Cache-Control", "no-cache");
    			writer = response.getWriter();
    			writer.write(string);
    		} catch (IOException e) {
    			LOG.error("",e);
    			dataJson.put("status", "201");
    			out.print(dataJson);
    		} finally {
    			if (null != writer) {
    				writer.flush();
    				writer.close();
    			}
    		}
    	}
    

     8 json to map

        public static Map<String, Object> jsonToMap(String paramJson ){
            Map<String, Object> paramsMap = new HashMap<String, Object>();
            paramsMap = (Map<String, Object>) JSONObject.fromObject(paramJson);
            return paramsMap;
        }

     9 str 判null或者""或者0

        /**
         * 判断obj是否为空或者0 是返True
         * @param obj
         * @return
         */
        private static Boolean isNullOrZero(Object obj) {
            Boolean flag = false;
            if(null !=obj){
                String str = String.valueOf(obj);
                if (("0").equals(str) || "".equals(str)) {
                    flag = true;
                }
            }else{
                flag = true;    
            }
            return flag;
        }

     10 ORACLE 日期比较可直接传 Date date =new Date() 参数比较  

        public List getMtlCtrlProductNo(String campsegId,String channelId,Date beginDate,String count){
            StringBuffer sql = new StringBuffer("SELECT PRODUCT_NO, COUNT(1)  FROM MTL_CONTACT_ACTIVITY_RCT_LOG  ");
            sql.append(" where CAMPSEG_ID = ?  AND CHANNEL_ID = ?  ");
            sql.append("  AND LOG_TIME >=  ?  ");
            sql.append(" GROUP BY PRODUCT_NO HAVING   COUNT(1) >= ?  ");
            List list = this.getJdbcTemplate().queryForList(sql.toString(),new Object[]{campsegId,channelId,beginDate,Integer.valueOf(count)});
            return list;
        }

     11 String filePath = ClassLoader.getSystemResource("config/ec/").getPath(); 当前class所在根目录下的config/ec/

    filePath = filePath.substring(1, filePath.length()).replace("/", "\");

    12 java 转千分位 百分数

        /**
         * 处理成千分位
         * @param number
         * @param pattern   ",###,###"||",###,###.00"
         * @return
         */
        public static String parseMoney(String number,String pattern){
            
            if(StringUtils.isEmpty(pattern)){
                pattern = ",###,###";
            }
             BigDecimal bd=new BigDecimal(number);
             DecimalFormat df=new DecimalFormat(pattern);
             return df.format(bd);
        }
        /**
         * 处理成百分数
         * @param number
         * @return
         */
        public static String parsePercent(String number){
                 double result=Double.valueOf(number);
                DecimalFormat df = new DecimalFormat("0.00%");
                return df.format(result);
        }
        
    DecimalFormat myformat = new DecimalFormat();
                   myformat.applyPattern("##,###");
                   amount = new BigDecimal(amount).divide(new BigDecimal(100)).toString();
                   amount = myformat.format(new BigDecimal(amount).setScale(0, RoundingMode.DOWN));
     

    13  sql like 方法  B.CAMPSEG_ID like   '%'|| ? ||'%' or B.CAMPSEG_NAME LIKE '%'|| ? ||'%'

    14 

        public List<MtlBotherContactConfig> getMtlBotherContactConfigList() {
            StringBuffer sql = new StringBuffer("select * from MTL_BOTHER_CONTACT_CONFIG where CONTACT_CONTROL_FLAG <> 0 ");
            List<MtlBotherContactConfig> list = getJdbcTemplate().query(sql.toString(),new RowMapper(){
                @Override
                public Object mapRow(ResultSet rs, int arg1) throws SQLException {
                    MtlBotherContactConfig obj = new MtlBotherContactConfig();
                    obj.setAvoidBotherFlag(rs.getLong("AVOID_BOTHER_FLAG"));
                    obj.setCampsegCityType(rs.getLong("CAMPSEG_CITY_TYPE"));
                    obj.setCampsegTypeId(rs.getLong("CAMPSEG_TYPE_ID"));
                    obj.setChannelId(rs.getString("CHANNEL_ID"));
                    obj.setContactControlFlag(rs.getLong("CONTACT_CONTROL_FLAG"));
                    obj.setParamDays(rs.getLong("PARAM_DAYS"));
                    obj.setParamNum(rs.getLong("PARAM_NUM"));
                    return obj;
                }
            });
            return list;
        }

     15 jdbc rowMapper

        /**
         * 加载接触频次控制渠道配置规则
         * @param sql
         * @param map
         */
        private void loadChannelContactRuleConfig(String sql, final Map<String, Map<String,Object>> map) {
            JdbcTemplate jt = SpringContext.getBean("jdbcTemplate", JdbcTemplate.class);
            jt.query(sql, new RowMapper() {
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    String channelId = rs.getString("CHANNEL_ID");
                    String channelName = rs.getString("CHANNEL_NAME");
                    Integer userLevelControlFlag = rs.getInt("USER_LEVEL_CONTROL_FLAG");//此渠道是否接受用户级的接触频次控制:0:不受控制,1:受控制
                    Integer channelDayCount = rs.getInt("CHANNEL_DAY_COUNT");//每个用户在这个渠道每天最多可以接受多少次
                    Integer channelMonthCount = rs.getInt("CHANNEL_MONTH_COUNT");//每个用户在这个渠道每个月最多可以接受多少次
                    if (StringUtil.isNotEmpty(channelId)) {
                        Map<String, Object> channelConfig = new HashMap<String,Object>();
                        channelConfig.put("channelId", channelId);
                        channelConfig.put("channelName", channelName);
                        channelConfig.put("userLevelControlFlag", userLevelControlFlag);
                        channelConfig.put("channelDayCount", channelDayCount);
                        channelConfig.put("channelMonthCount", channelMonthCount);
                        map.put(channelId, channelConfig);
                    }
                    return null;
                }
            });
        }

      sql.append("SELECT * FROM USER");
            return this.getJdbcTemplate().query(sql.toString(),
                ParameterizedBeanPropertyRowMapper.newInstance(user.class));

    ///INSERT_MESSAGE_SQL = INSERT INTO BS_SMS_PUSH_R(ID,TASK_ID,CHANNEL_ID,MSISDN,SUBJECT,STATUS,SEND_COUNT,CREATE_TIME,UPDATE_TIME) VALUES
    (:id,:taskId,:channelId,:productNo,:msg,:status,:sendCount,:createTime,:updateTime)
                String sql = MpmConfigure.getInstance().getProperty("INSERT_MESSAGE_SQL");
                SqlParameterSource[] params = SqlParameterSourceUtils.createBatch(msgList.toArray());
                SimpleJdbcTemplate messageSimpleJdbcTemplate = SpringContext.getBean("messageSimpleJdbcTemplate", SimpleJdbcTemplate.class);
                messageSimpleJdbcTemplate.batchUpdate(sql, params);
  • 相关阅读:
    修改项目名称
    Servlet中request、response、ServletContext 及其常用方法
    Servlet生命周期、常用提交方式、中文乱码问题、重定向和请求转发
    JavaScript基础(三) 事件
    JavaScript基础(二) DOM
    JavaScript基础(一)
    css基础:样式之定位、样式之隐藏、二级菜单、多个列表转表格、图片精灵技术
    css基础:表格样式、一级菜单、BFC浮动影响
    css基础及其实例:常用选择器、颜色五中写法、字体样式、自定义字体、盒模型及其样式设置
    HTML元素标签及表单元素详解
  • 原文地址:https://www.cnblogs.com/clds/p/4990570.html
Copyright © 2011-2022 走看看