简体   繁体   English

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

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

I want to select query from my database. 我想从数据库中选择查询。 I need to find from a list because it has many search items in the same query. 我需要从列表中查找,因为它在同一查询中有很多搜索项。 So I want to get the list to do that. 因此,我想获得执行此操作的列表。 Select query works very well when I add Model.addattribute . 当我添加Model.addattribute时,选择查询效果很好。 But I don't want that. 但是我不想要那个。 I want to do it from Ajax. 我想从Ajax做到这一点。 So I want to pass the list to another control which is written for ajax. 所以我想将列表传递给为ajax编写的另一个控件。 So please someone help me to do that. 所以请有人帮我做到这一点。

This is my controller class which get my page 这是我的控制器类,可获取我的页面

@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";
    }

I want to pass unitsSLSI list to my another controller? 我想将unitsSLSI列表传递给另一个控制器吗? The rest service (ajax) controller is 其余服务(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);
    }

when I add this cord 当我添加这根线

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

I want to get unitList from my previous controller because it has my search list. 我想从以前的控制器中获取unitList ,因为它具有我的搜索列表。 How can I do that? 我怎样才能做到这一点?

删除@JsonIgnore ,使您的响应变得充满生气...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将HashMap对象从一个方法传递到同一个Spring MVC控制器类中的另一个方法 - How to pass HashMap object from one method to another method in same Spring MVC controller class 如何将列表从控制器传递到jsp并在Spring MVC中的javascript中对其进行迭代 - how to pass a list from controller to jsp and iterate it in javascript in spring mvc 如何将列表从视图传递到 Spring MVC 和 thymeleaf 中的 controller? - How to pass a list from the view to the controller in Spring MVC with thymeleaf? 如何从一个Spring MVC控制器获取变量到另一个 - How to get variables from one Spring MVC Controller to Another 无法从一个控制器重定向到另一控制器-Spring MVC - Unable to redirect from one controller to another controller-Spring MVC Spring MVC将一个值列表从JSP页面传递给控制器 - Spring MVC pass a list of values into controller from JSP page Spring MVC将多个列表从控制器传递到jsp - Spring MVC Pass multiple list from controller to jsp 将li的列表从客户端传递给Spring MVC控制器 - Pass a list of li from client to Spring MVC controller 如何将对象从一个控制器传递到另一个控制器 - How to pass an object from one controller to another controller 如何将嵌套的列表元素传递给spring mvc中的控制器 - How to pass nested list element to the controller in spring mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM