【问题标题】:Avoid @ModelAttribute("attr") loading for every URL避免为每个 URL 加载 @ModelAttribute("attr")
【发布时间】:2015-05-06 09:33:03
【问题描述】:

我在 jsp 中有一个下拉菜单,我使用 @modelAttribute 从数据库中填充数据。但是,每当 url 在该 url 执行模型属性代码运行之前命中并意外命中数据库时......是否有任何方法可以避免这种情况...... 我的代码是

@ModelAttribute("courseList")
    public Map<String, String> gerCourseNameList(HttpSession session,
        HttpServletRequest httpSevletRequest, HttpServletResponse response,
        ModelMap model) throws IOException {
    Map<String, String> map = null;

 ------ My code here------

}

我的日志文件在这里

 [DEBUG] SessionFilter| Url :http://localhost:8080/EnKalviV1/studentallocation.htm
 [06 May 2015 15:01:11] [Inst Id: INS | Branch Id: BR001 | User Id: bradm1 | Session Id: 97910CBDA9FF68175302717842E9923F]
 [DEBUG] LoggingAspect| Class Name :com.jaw.student.controller.StudentAllocationController,Calling gerCourseNameList() method.
 [06 May 2015 15:01:11] [Inst Id: INS | Branch Id: BR001 | User Id: bradm1 | Session Id: 97910CBDA9FF68175302717842E9923F]

即使对于该控制器中的 ajax 调用,此代码也在运行...

如何避免这种情况......

【问题讨论】:

标签: java spring modelattribute


【解决方案1】:

只要收到不包含该名称的模型属性的请求,就会运行此方法。

给你的控制器类添加注解

@SessionAttributes ({"courseList"})

这将导致模型属性被添加到会话中,然后在每次请求时将其添加回模型,否则会导致方法被执行。

【讨论】:

    猜你喜欢
    • 2021-12-16
    • 1970-01-01
    • 2011-06-15
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 2011-09-03
    • 1970-01-01
    相关资源
    最近更新 更多