java 随笔记录(一)

来源:互联网 发布:国家大数据专业委员会 编辑:程序博客网 时间:2024/06/06 04:10

/***********************sql里的时间转换***********************************************************


IFNULL(date_format(ci.period_start,'%Y.%m.%d'),"") as period_start,


/**********************************************************************************

1.微信证书储存路径

#CERTIFICATE=E:\\WxCertificate\\zc\\apiclient_cert.p12   windows系统的路径

CERTIFICATE=/home/server/zc/WxCertificate/apiclient_cert.p12     服务器的路径

#CERTIFICATE=/Users/zhangshuang/Desktop/WxCertificate/apiclient_cert.p12   本地的路径


2.*************************************判断list是否为空***************************************

if(list!=null && !list.isEmpty()){

这个里面取list中的值

}else{

做其他处理

}


3.******************equals方法比较的是字符串的内容是否相同**************************

 if(str1.equals(str2) ){

System.out.println("字符串相等");

}else{

System.out.println("字符串不相等");

}


4.*************************************字符串转int*************************************

String s="111";

        int a=Integer.parseInt(s);

        System.out.println(a);


5..***************打印list的每个map元素***************

counpActivity_id_List=orderInfoDao.getCounpActivityIDList(mapParam);

for (int i = 0; i < counpActivity_id_List.size(); i++) {

System.out.println("第二个是:"+counpActivity_id_List.get(i).toString());

}

6..**************************打印map的每个键值对儿元素**************************


   for (String key : mapParam.keySet()) {   

           System.out.println("传进来的mapkey= "+ key + " 传进来的map value= " + mapParam.get(key));

     }

7.**********************判断一个字符串是否为空,首先就要确保他不是null,然后再判断他的长度************************

  String str = xxx;

  ifstr != null && str.length() != 0 { }


8.以下是Java 判断字符串是否为空的四种方法:


方法一最多人使用的一个方法, 直观, 方便, 但效率很低:

                                    if(s == null ||"".equals(s));
方法二比较字符串长度, 效率高, 是我知道的最好一个方法:

                      if(s == null || s.length() <= 0);
方法三Java SE 6.0 才开始提供的方法, 效率和方法二几乎相等, 但出于兼容性考虑, 推荐使用方法二.

                     if(s == null || s.isEmpty());

方法四这是一种比较直观,简便的方法,而且效率也非常的高,与方法二、三的效率差不多:

                     if (s == null || s == "");

 

注意:s == null 是有必要存在的.

  如果 String 类型为null, 而去进行 equals(String)  length() 等操作会抛出java.lang.NullPointerException.

  并且s==null 的顺序必须出现在前面,不然同样会抛出java.lang.NullPointerException.

  如下Java代码:

  String str = null;

  if(str.equals("") || str= == null){//会抛出异常

            System.out.println("success");

  }

  // "".equals(str);后置确保不会遇null报错。

9.*********************************获取当前时间*******************************************************


  Date date = new Date();

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            String time = sdf.format(date);

            mapReturn.put("time", time);


       //截取开始时间

//             String ad_start_times=map.get("ad_start_times").toString();

//             String promotion_start_times=ad_start_times.substring(0,10);

//               mapReturn.put("promotion_start_times",promotion_start_times );


//转换时间************横岗或冒号************

IFNULL(date_format(oi.appoint_end_time,'%Y/%m/%d %H:%i:%s'),"") as order_date,

10./**************************3目运算符*******************************************************  


Int A,B,C; 

A=2; 

B=3; 

C=A>B ? 100 :200; 

这条语句的意思是,如果A>B的话,就将100赋给C,否则就将200赋给C


10./*************************sql 格式化日期输出********************************************  

IFNULL(date_format(oi.appoint_start_time,'%Y%m%d'),"") as sort_date,


11./*****************************接口的请求头****************************************************  


@RequestBody Map<String, Object> maps

@RequestParam String param


微信端

参数:

(@RequestParam String param)


  

    @SuppressWarnings("finally")

    @RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST)

    public @ResponseBody

    Object getOrderDetail(@RequestParam String param, HttpServletRequest request, HttpServletResponse response,

            ModelMap model) throws Exception {

        response.setHeader("Access-Control-Allow-Origin", "*");

        Map<String, Object> maps = JsonUtil.transStringToMap(param);

       

     


Map<String, Object> maps = JsonUtil.transStringToMap(param);


管理端

参数:

(@RequestBody Map<String, Object> maps)


  Object updateSubscribe(@RequestBody Map<String, Object> maps, HttpServletRequest request, HttpServletResponse response,

                ModelMap model) throws Exception


21./*************时间差********************************************************************  


      Date firstDate = new Date();

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

      

      String time = sdf.format(firstDate);

          System.out.println("当前时间是"+time);

          

      String firstTime = "2017-02-20 15:40:07";

      Date date = sdf.parse(firstTime);

          System.out.println("第一次时间"+firstTime);

      

//得到两个日期对象的总毫秒数

long firstDateMilliSeconds = firstDate.getTime();

long secondDateMilliSeconds = date.getTime();

//得到两者之差

long firstMinusSecond = firstDateMilliSeconds - secondDateMilliSeconds;

//毫秒转为秒  

long milliSeconds = firstMinusSecond;

int totalSeconds = (int)(milliSeconds / 1000);


System.out.println("相差时间===="+totalSeconds);