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.

  • 相关阅读:
    语言基础
    进制转换
    ado属性扩展
    ado数据模型和数据访问类,泛型集合
    完整的修改和删除
    完整的删除
    修改
    类库
    接口
    抽象类
  • 原文地址:https://www.cnblogs.com/rixiang/p/4935556.html
Copyright © 2011-2022 走看看