Map<Long,Account> map = new HashMap<Long,Account>(); for(int i=0;i<list.size();i++){ Account account = (Account)list.get(i); map.put(account.getId(),account); }
后台的
package com.iport.site.controller; import com.iport.base.basecontroller.BaseController; import com.iport.exception.SystemException; import com.iport.site.model.SiteSettingEntity; import com.iport.site.service.SiteSettingService; import com.iport.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.*; @Controller @Scope("prototype") @RequestMapping("/site/") public class SiteSettingController extends BaseController { @Autowired private SiteSettingService siteSettingService; @RequestMapping("listUI.html") public String listUI(Model model) { System.out.println("111111111111111111"); try { List<SiteSettingEntity> list = siteSettingService.querySiteSettingList(); Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < list.size(); i++) { SiteSettingEntity siteSettingEntity = list.get(i); map.put(siteSettingEntity.getKey(), siteSettingEntity.getValue()); } model.addAttribute("map", map); //System.out.println("map================" + map.get("SiteName").toString()); return Common.BACKGROUND_PATH + "/site/list"; } catch (Exception e) { throw new SystemException(e); } } }
取值的话就是页面中
${map.key} 或者${map['key']}来显示值