如何设计Servlet容器启动时加载多个数据到内存

1.这是代码方面的设计

package com.fanli.mall.platform.freemarker;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.fanli.mall.service.ClassifyService;
import com.fanli.mall.vo.ClassifyVo;

public class ClassifySelectListener implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        ClassifyVo classifyVo = new ClassifyVo();
        classifyVo.setParentId(0);
        ApplicationContext ctx = WebApplicationContextUtils
                .getWebApplicationContext(servletContext);
        ClassifyService classifyService = (ClassifyService) ctx
                .getBean("classifyService");
        List<ClassifyVo> list = classifyService.findList(classifyVo);

        Map<Integer,List<ClassifyVo>> map = new HashMap<Integer,List<ClassifyVo>>();
        ClassifyVo classifyVoChild = new ClassifyVo();
        for (ClassifyVo classifyVo2 : list) {
            classifyVoChild.setParentId(classifyVo2.getId());
            classifyVoChild.setIsEnable(1);
            List<ClassifyVo> listChildren = classifyService.findList(classifyVoChild);
            for (ClassifyVo classifyVo3 : listChildren) {
                if(classifyVo3.getIsEnable()==0){
                    listChildren.remove(classifyVo3);
                }
            }
            map.put(classifyVo2.getId(), listChildren);

        }
        servletContext.setAttribute("classifyVos", map);
    }

}

2.这是数据库方面的设计:
这是数据库的设计,要想加载多的数据到内存中就必须要在一个表中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值