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);

 

posted @ 2015-11-24 09:43  穿林度水  阅读(375)  评论(0编辑  收藏  举报