Action
Public String showallexperts () { try { list= Rescueexpertsservice.findrescueexpertslist (); springcontextassist. Getbean (ijsongenerator.class);//Get to transfer mechanism = json.getjsonstring (list); //Convert list to JSON
Catch (Exception e) {
return "Rescue_experts_mapview"
}
Springcontextassist
PackageCom.hfky.crs.busi.service;Importorg.springframework.beans.BeansException;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.ApplicationContextAware;ImportOrg.springframework.stereotype.Service; @Service Public classSpringcontextassistImplementsApplicationcontextaware {Private StaticApplicationContext context; @Override Public voidSetapplicationcontext (ApplicationContext ApplicationContext)throwsbeansexception {Context=ApplicationContext; } Public Static<T> T Getbean (String beanname,class<t>CLS) { returnCls.cast (Context.getbean (beanname)); } Public Static<T> T Getbean (class<t>type) { returnContext.getbean (type); }}
Ijsongenerator.class
PackageCom.hfky.crs.busi.service;Importjava.util.List;ImportCom.google.gson.ExclusionStrategy; Public InterfaceIjsongenerator { Publicijsongenerator Applydateformat (String pattern); /*** Convert an object instance to a JSON string *@paramtarget object to convert *@returnJSON string*/ PublicString getjsonstring (Object target); /*** Get JSON String *@paramTarget *@parames *@return */ PublicString getjsonstring (Object target,exclusionstrategy es); /** * * @paramTarget *@paramexcluded *@return */ PublicString getjsonstring (Object target,class<?>... excluded); /*** Get object instances from JSON String *@param<Type> Result class type *@paramJSON JSON String *@paramCLS Type *@returntarget Object*/ Public<Type> Type getjsonobject (String json,class<type>CLS); /** * @param<Type> *@paramJSON *@paramCLS *@return */ Public<Type> list<type> Getlistfromjson (String json,class<type>CLS); }
Convert list data form to JSON form