1. 程式人生 > >Java 後端封裝接收值的通用方法

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