标签:target etl 类型 gen slist 数据 spring override pack
Action
public String showAllExperts(){ try { list=rescueExpertsService.findRescueExpertsList(); IJsonGenerator json = SpringContextAssist.getBean(IJsonGenerator.class); //获取转机制 toMapList = json.getJsonString(list);//将List转化为Json
} catch (Exception e) {
e.printStackTrace();
}
return "rescue_experts_mapview";
}
SpringContextAssist
package com.hfky.crs.busi.service; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; @Service public class SpringContextAssist implements ApplicationContextAware { private static ApplicationContext context; @Override public void setApplicationContext( ApplicationContext applicationContext ) throws BeansException { context = applicationContext; } public static <T> T getBean( String beanName,Class<T> cls ) { return cls.cast( context.getBean( beanName ) ); } public static <T> T getBean(Class<T> type){ return context.getBean(type); } }
IJsonGenerator.class
package com.hfky.crs.busi.service; import java.util.List; import com.google.gson.ExclusionStrategy; public interface IJsonGenerator { public IJsonGenerator applyDateFormat(String pattern); /** * 将对象实例转换为json字符串 * @param target 待转换的对象 * @return json字符串 */ public String getJsonString(Object target); /** * 获取json字符串 * @param target * @param es * @return */ public String getJsonString(Object target,ExclusionStrategy es); /** * * @param target * @param excluded * @return */ public String getJsonString(Object target,Class<?> ... excluded); /** * 从json字符串获取对象实例 * @param <Type> 结果类类型 * @param json json字符串 * @param cls 类型 * @return 目标对象 */ public <Type> Type getJsonObject(String json,Class<Type> cls ); /** * @param <Type> * @param json * @param cls * @return */ public <Type> List<Type> getListFromJson(String json,Class<Type> cls); }
标签:target etl 类型 gen slist 数据 spring override pack
原文地址:http://www.cnblogs.com/flytogalaxy/p/7649924.html