| | |
| | | return getSession().getServletContext(); |
| | | } |
| | | |
| | | /* |
| | | * 获取将对象转换成json格式 |
| | | */ |
| | | public static String toJson(Object obj){ |
| | | Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
| | | return gson.toJson(obj); |
| | | } |
| | | |
| | | public static String chageDateToString(Date time,String type){ |
| | | String msg = ""; |
| | | SimpleDateFormat sdf = new SimpleDateFormat(type); |
| | | msg = sdf.format(time); |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @param datetype 需要解析的日期的格式如:"yyyy-MM-dd HH:mm:ss" |
| | | * @return 得到对应的gson对象 |
| | | */ |
| | | public static Gson getGson(String datetype){ |
| | | return new GsonBuilder().setDateFormat(datetype).create(); |
| | | } |
| | | |
| | | /** |
| | | * 获取默认的gson对象 |
| | | * @return |
| | | */ |
| | | public static Gson getGson(){ |
| | | return new Gson(); |
| | | } |
| | | |
| | | |
| | | public static <T> T getObject(String jsonstring,Type listtype){ |
| | | Gson gson=new Gson(); |
| | | T t=null; |
| | | try { |
| | | t=gson.fromJson(jsonstring, listtype); |
| | | } catch (JsonSyntaxException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return t; |
| | | } |
| | | |
| | | /** |
| | | * get方式的http请求 |
| | | * |
| | |
| | | } catch (IOException e) { |
| | | response.set(0); |
| | | String message = e.getMessage(); |
| | | response.setData(message); |
| | | response.setMsg(message); |
| | | } finally { |
| | | // 关闭资源 |
| | | if (null != bufferedReader) { |
| | |
| | | } catch (IOException e) { |
| | | String message = e.getMessage(); |
| | | response.set(0); |
| | | response.setData(message); |
| | | response.setMsg(message); |
| | | } finally { |
| | | // 关闭资源 |
| | | if (null != bufferedReader) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 用于Video 的Http接口请求 |
| | | * 执行GET请求,传入Map参数和Url,获取响应 |
| | | * 这个对原始的doGet方法进行了调用,对结果进行后续逻辑再处理,属于定制化的接口了. |
| | | */ |
| | | public static Response4Http doGet(String httpUrl, Map<String, ?> params) { |
| | | Response4Http responseResult = new Response4Http<>(); |
| | |
| | | Integer httpResponseCode = response.getCode(); |
| | | String responseJson = (String) response.getData(); |
| | | if(httpResponseCode == 1) { //请求成功 |
| | | Response4Http responseHttp = HttpUtil.getGson().fromJson(responseJson, Response4Http.class); |
| | | Response4Http responseHttp = JsonUtil.getGson().fromJson(responseJson, Response4Http.class); |
| | | if(responseHttp.getCode() == 0 ) { //接口返回状态码为成功 |
| | | //返回信息有 data属性 |
| | | if(responseHttp.getData()!=null) { |