package com.chen.base;

import java.beans.PropertyEditorSupport;

import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

/**
 * 
* 类名称:BaseController   
* 类描述:BaseController 控制器基类   
* 创建人:chenguoji   
* 创建时间:2017年3月31日 下午3:02:16   
*
 */
public class BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 初始化数据绑定
	 * 1. 将所有传递进来的String进行HTML编码,防止XSS攻击
	 * @param binder
	 */
	@InitBinder
	protected void initBinder(WebDataBinder binder) {
		// String类型转换,将所有传递进来的String进行HTML编码,防止XSS攻击
		binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
			@Override
			public void setAsText(String text) {
				setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
			}

			@Override
			public String getAsText() {
				Object value = getValue();
				return value != null ? value.toString() : "";
			}
		});
	}
	
	/**
	 * 重定向至地址 url
	 * @param url 请求地址
	 * @return
	 */
	protected String redirectTo(String url) {
		StringBuilder rto = new StringBuilder("redirect:");
		rto.append(url);
		return rto.toString();
	}
}
最近下载更多
微信网友_6248713511227392  LV11 2022年12月5日
秋枫花落叶  LV2 2022年10月24日
liuxiao2  LV16 2022年10月13日
微信网友_5966087716769792  LV9 2022年10月11日
hkxyyz  LV6 2022年5月11日
893213895  LV18 2021年12月16日
543666826  LV33 2021年11月20日
tanglitao  LV6 2021年10月19日
2715406348  LV3 2021年5月21日
啊啊DVD v但是  LV4 2021年3月29日
最近浏览更多
夜上清元  LV8 3月15日
可是不知道么  LV23 2月5日
try8023  LV18 1月16日
WBelong  LV7 2023年12月27日
3175665836  LV2 2023年11月25日
aaaaaacv 2023年9月20日
暂无贡献等级
逍遥2020  LV11 2023年8月1日
微信网友_6536105093189632  LV1 2023年6月26日
cunbie  LV4 2023年6月13日
tookaaa  LV1 2023年5月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友