首页 > 编程语言 > 详细

springMvc get参数转码

时间:2015-09-15 16:44:24      阅读:269      评论:0      收藏:0      [点我收藏+]
//字符串转参数转码
import java.beans.PropertyEditorSupport;
import java.io.UnsupportedEncodingException;

import org.apache.commons.lang.StringUtils;

public class CustomStringEditor extends PropertyEditorSupport{
	
	private String charset;

	public CustomStringEditor() {}
	
	public CustomStringEditor(String charset) {
		this.charset = charset;
	}
	
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		try {
			if (StringUtils.isNotBlank(text)) {
				text = ConverStr.changeCharset(text,ConverStr.ISO_8859_1, charset);
			}
			setValue(text);
			return;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	public void setCharset(String charset) {
		this.charset = charset;
	}
	
}

//controller应用
@InitBinder
public void initBinder(WebDataBinder binder, HttpServletRequest request) {
    if ("GET".equalsIgnoreCase(request.getMethod())) {
        binder.registerCustomEditor(String.class, new CustomStringEditor(ConverStr.UTF_8));
    }
}


springMvc get参数转码

原文:http://my.oschina.net/haochenhh/blog/506344

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