簡體   English   中英

如何在Spring MVC中將LIST從一個控制器傳遞到另一個控制器

[英]How to pass LIST from one controller to another controller in spring mvc

我想從數據庫中選擇查詢。 我需要從列表中查找,因為它在同一查詢中有很多搜索項。 因此,我想獲得執行此操作的列表。 當我添加Model.addattribute時,選擇查詢效果很好。 但是我不想要那個。 我想從Ajax做到這一點。 所以我想將列表傳遞給為ajax編寫的另一個控件。 所以請有人幫我做到這一點。

這是我的控制器類,可獲取我的頁面

@RequestMapping(path = "/applicationManage")
    public String viewApplicationPage(Model model) {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        long userId = 0;
        String agency = "";
        String units = "";
        List<String> unitsSLSI;

        if (principal != null && principal instanceof AuthenticatedUser) {
            AuthenticatedUser auth = (AuthenticatedUser) principal;
            userId = auth.getUserId();
            agency = auth.getAgency();
            unitsSLSI = auth.getJobUnits();

        }
        return "applicationManage";
    }

我想將unitsSLSI列表傳遞給另一個控制器嗎? 其余服務(ajax)控制器是

@RequestMapping(value = "/SLSIApp", produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET)
    @JsonIgnore
     public ResponseEntity<List<SLSNotification>> listAllSLSI(List<String> unitList) {
        List<SLSNotification> appbyUserID = jservice.getApplicationsByUnit(unitList);
        if (appbyUserID.isEmpty()) {
            return new ResponseEntity<List<SLSNotification>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
        }
        System.out.println("hibernate query " + new ResponseEntity<List<SLSNotification>>(appbyUserID, HttpStatus.OK));
        return new ResponseEntity<List<SLSNotification>>(appbyUserID, HttpStatus.OK);
    }

當我添加這根線

  List<SLSNotification> appbyUserID = jservice.getApplicationsByUnit(unitList); 

我想從以前的控制器中獲取unitList ,因為它具有我的搜索列表。 我怎樣才能做到這一點?

刪除@JsonIgnore ,使您的響應變得充滿生氣...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM