b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

JAVA网络数据字典,包括基本数据加载

电脑杂谈  发布时间:2020-06-08 03:14:28  来源:网络整理

数据加载中_java ztree异步加载数据_java中数据字典加载

因为使用了数据字典,所以整个网站使用相同的副本. 因此java中数据字典加载,当网站启动时,查询可以放置在ServletContext中. 这样一来,每次请求结束时就无需多次查询.

数据加载中_java ztree异步加载数据_java中数据字典加载

-使用过滤,不好. 由于此请求已结束,因此您必须拦截过滤器.

数据加载中_java ztree异步加载数据_java中数据字典加载

-使用Servlet不好,因为此请求到来,所以必须执行相应的servlet路径

数据加载中_java ztree异步加载数据_java中数据字典加载

-因此,我们需要一种技术. 启动Tomcat时,它将加载一次,以后将不再加载.

java ztree异步加载数据_java中数据字典加载_数据加载中

答案: 您可以通过将参数放入全局上下文容器中. 然后可以访问所有Web组件对象.

答案: 对于不在Spring容器中的对象java中数据字典加载,请在Spring容器中获取对象. Spring框架提供了一个WebApplicationContextUtils工具类来获取Spring容器对象.

package cn.gzsxt.listener;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import cn.gzsxt.service.DictionaryService;
public class DictionaryCreateListener implements ServletContextListener {
    //@Autowired
    //private DictionaryService dictionaryService;
    
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //
        WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
        DictionaryService dictionaryService = applicationContext.getBean(DictionaryService.class);
        List<Map<String, Object>> dictionarys = dictionaryService.findAllDictionary();
        ServletContext context = sce.getServletContext();
        context.setAttribute("dictionarys", dictionarys);
        
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        
    }
}

web.xml的配置


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-237891-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 李宇杰
        李宇杰

        离衰退的日子不远了

      • 李昉
        李昉

        其实也就等同于今后任何国家到美国去巡航

      • 云波
        云波

        你不靠原始股上市能发大财

      热点图片
      拼命载入中...