• list转map 键值对


    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']}来显示值
  • 相关阅读:
    爬取豆瓣电影信息
    MongoDB的聚合操作以及与Python的交互
    matplotlib简单示例
    MongoDB基本操作
    K近邻算法
    Scrapy爬取博客园精华区内容
    爬虫失败
    Markdown基本使用方法
    UITableViewCell高度自适应变化
    KVO和NSNotification
  • 原文地址:https://www.cnblogs.com/xuerong/p/5287356.html
Copyright © 2020-2023  润新知