首页 > 其他 > 详细

Chinese Messy Code of String

时间:2015-11-04 13:13:54      阅读:278      评论:0      收藏:0      [点我收藏+]

I‘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.

技术分享

Chinese Messy Code of String

原文:http://www.cnblogs.com/rixiang/p/4935556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!