Java 后端封装接收值的通用方法

1、前端 iso-8859-1,需要进行转码  ,需要先测试一下字符 ,然后再看一下是否需要转码,前面有介绍怎么判断前端传来的字符。

   /**
     * 封装页面VO数据
     * 
     * @param request
     * @return
     * @throws UnsupportedEncodingException 
     */
    private ImpCompanyQueryVo copyProperties1(HttpServletRequest request) throws UnsupportedEncodingException {
        ImpCompanyQueryVo vo = new ImpCompanyQueryVo();

        Enumeration<String> param = request.getParameterNames();
        while (param.hasMoreElements()) {
            String name =  param.nextElement();
            try {
                BeanUtils.setProperty(vo, name, new String(request.getParameter(name).getBytes("iso-8859-1"), "UTF-8"));
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return vo;
    }

猜你喜欢

转载自blog.csdn.net/zhangjiaqianghh/article/details/86157806