zoukankan      html  css  js  c++  java
  • 星涛:JSP开发助手函数

    package com.botao.utils;
    
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.nio.charset.StandardCharsets;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.Map;
    
    public class Helper {
        public static void responseJSON(HttpServletResponse resp , Map<Object, Object> map) throws IOException {
            resp.setContentType("application/json;charset=UTF-8");
            resp.getWriter().print(new ObjectMapper().writeValueAsString(map));
        }
        public static String toJSONString(Map<Object, Object> map) throws IOException {
            return new ObjectMapper().writeValueAsString(map);
        }
        public static String toMd5str(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
            MessageDigest m=MessageDigest.getInstance("MD5");
            m.update(str.getBytes(StandardCharsets.UTF_8));
            byte[] s =m.digest();
            StringBuilder result= new StringBuilder();
            for (byte b : s) {
                result.append(Integer.toHexString((0x000000ff & b) | 0xffffff00).substring(6));
            }
            return result.toString();
        }
    }
  • 相关阅读:
    python之各种包
    正则表达式
    import/模块的导入
    迭代器/可迭代对象/生成器
    Day2 列表list
    Day1 字符串格式化
    Day1 字符编码及编码函数
    Python 学习笔记 之 随着学习不断更新的Python特性搜集
    Day1 input&print
    Newtonsoft.Json日期转换
  • 原文地址:https://www.cnblogs.com/botaoJava/p/13828549.html
Copyright © 2011-2022 走看看