zoukankan      html  css  js  c++  java
  • Chinese Messy Code of String

    It's very strange that I found the messy code.I 've never seen this before.

    this is the java code:

        /**
         * list
         * 
         * @throws UnsupportedEncodingException
         */
        @RequestMapping(value = "/list", method = RequestMethod.GET)
        public String list(Long adminId, String operation, Date beginDate,
                Date endDate, Pageable pageable, ModelMap model)
        {
            if (null == endDate)
            {
                endDate = new Date();
            }
    
            //query 30day before by default
            if (null == beginDate)
            {
                beginDate = DateUtils.addDays(endDate, -30);
            }
            List<LogConfig> logConfigs = logConfigService.getAll();
            List<Admin> admins = adminService.findAll();
            model.addAttribute("admins", admins);
            model.addAttribute("logConfigs", logConfigs);
            model.addAttribute("adminId", adminId);
            model.addAttribute("page", logService.findPage(adminId, operation,
                    beginDate, endDate, pageable));
            model.addAttribute("operation", operation);
            model.addAttribute("beginDate", beginDate);
            model.addAttribute("endDate", endDate);
            return "/admin/log/list";
        }

    And the String parameter "operation" was always messy code. 

    I thought it was the matter of FreeMarker. If the front end code gave a String as a object.so background program would got a address of object.

    but that is wrong.It is just different with the messy code.

    Finally I added this two lines code:

            if (operation != null)
            {
                operation = (new String(operation.getBytes("ISO-8859-1"), "utf-8"))
                        .trim();
            }

    that's ok.

    but that's not the best way.

    tomcat's encoding setting is the key of the problem.

  • 相关阅读:
    Java框架第二次课
    知识扩展1——最大似然估计
    知识扩展2——熵 ,KL散度,交叉熵,JS散度,Wasserstein 距离(EarthMover距离)
    知识扩展3——广义线性模型GLM
    3 逻辑回归
    朴素贝叶斯
    GAN 的后序
    mysql 多个字段字符串合并成一个字段
    qt离线下载
    “用户”,你凭什么说改框架?
  • 原文地址:https://www.cnblogs.com/rixiang/p/4935556.html
Copyright © 2011-2022 走看看