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.

  • 相关阅读:
    vue-router 实践
    修改vue中<router-link>的默认样式
    JSON.parse() 与 JSON.stringify() 的区别
    JS 中的异步操作
    CSS3 box-sizing:border-box的好处
    element ui 栅格布局
    css overflow用法
    koa中间件机制
    canvas 入门
    前端面试题:淘宝首页用了多少种标签
  • 原文地址:https://www.cnblogs.com/rixiang/p/4935556.html
Copyright © 2011-2022 走看看