解码实体的所有String类型字段。用于解决导出时输入参数中文乱码有关问题,和前台encodeURI(encodeURI("中文字符"))方法结合使用
解码实体的所有String类型字段。用于解决导出时输入参数中文乱码问题,和前台encodeURI(encodeURI("中文字符"))方法结合使用
/**
* 解码实体的所有String类型字段。用于解决导出时输入参数中文乱码问题,和前台encodeURI(encodeURI("中文字符"))方法结合使用
* 。
*
* @param entity
* 待解码实体
* @throws Exception
*/
public static <T> void decodeEntityStringFileds(
T entity) throws Exception
{
PropertyDescriptor[] propertyDescriptors = org.springframework.beans.BeanUtils.getPropertyDescriptors(entity.getClass());
for (PropertyDescriptor pd : propertyDescriptors) {
if (pd.getPropertyType().isAssignableFrom(String.class)) {
String filedName = pd.getName();
String filedValue = org.apache.commons.beanutils.BeanUtils.getProperty(entity, filedName);
if (StringUtils.isNotBlank(filedValue)) {
filedValue = URLDecoder.decode(filedValue, "UTF-8");
org.apache.commons.beanutils.BeanUtils.setProperty(entity, filedName, filedValue);
}
}
}
}
/**
* 解码实体的所有String类型字段。用于解决导出时输入参数中文乱码问题,和前台encodeURI(encodeURI("中文字符"))方法结合使用
* 。
*
* @param entity
* 待解码实体
* @throws Exception
*/
public static <T> void decodeEntityStringFileds(
T entity) throws Exception
{
PropertyDescriptor[] propertyDescriptors = org.springframework.beans.BeanUtils.getPropertyDescriptors(entity.getClass());
for (PropertyDescriptor pd : propertyDescriptors) {
if (pd.getPropertyType().isAssignableFrom(String.class)) {
String filedName = pd.getName();
String filedValue = org.apache.commons.beanutils.BeanUtils.getProperty(entity, filedName);
if (StringUtils.isNotBlank(filedValue)) {
filedValue = URLDecoder.decode(filedValue, "UTF-8");
org.apache.commons.beanutils.BeanUtils.setProperty(entity, filedName, filedValue);
}
}
}
}