2017-12-11 3 views
0

私のデータベースからクエリを選択したいと思います。同じクエリ内に多くの検索項目があるので、リストから検索する必要があります。だから私はそれをするためのリストを取得したい。選択クエリはModel.addattributeを追加するとうまく機能します。しかし、私はそれを望んでいません。私はAjaxからやりたいだから私はajaxのために書かれた別のコントロールにリストを渡したい。だから誰かが私にそれを手伝ってください。spring mvcのあるコントローラから別のコントローラへLISTを渡す方法

これは私のページ

@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リストを渡したいですか?私はそれが私の検索リストを持っているので、私の以前のコントローラからunitListを取得したい

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

このコードを追加するときに、残りのサービス(アヤックス)コントローラが

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

です。どうやってやるの?

答えて

2

あなたが応答として@JsonIgnoreを削除します。また、そのlistAllSLSIに@ResponseBodyを追加する必要があるかもしれません

+0

... ingoredます。 –

+0

いいえ、彼は必要なものすべてを返すように応答エンティティを返しています。 – Antoniossss

+0

@Antoniossss .. How to this ...私はこれを行うことを理解しています –

関連する問題