如何在Spring mvc中将LIST从一个控制器传递到另一个控制器

时间:2017-12-11 18:50:16

标签: java jsp spring-mvc spring-boot

我想从我的数据库中选择查询。我需要从列表中查找,因为它在同一查询中有许多搜索项。所以我想得到清单来做到这一点。添加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,因为它有我的搜索列表。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

在您收到反应时删除@JsonIgnore ...