2015-09-01 61 views
-1

我在Spring MVC中創建了一個內容管理系統,並嘗試從我的數據庫中獲取審閱。一切正常,但當我點擊電影名稱時,我想將評論值傳遞給JSP審閱框;我嘗試了一切,但值並沒有傳遞給JSP。這裏是我的控制器代碼:將單一模型屬性傳遞給JSP

@RequestMapping(value = "/getmoviereviewbyid/{id}", method = RequestMethod.GET) 
    public @ResponseBody ModelAndView getMovieReviewById(
      @PathVariable(value = "id") String movie_id, 
      HttpServletRequest request, HttpServletResponse response) 
      throws UnsupportedEncodingException { 
      response.addHeader("Access-Control-Allow-Origin", "*"); 
      ModelAndView model = new ModelAndView(); 
      int i=0; 
       try { 
        if (movie_id != null) { 
         List<MovieReviewModel> tagList = new ArrayList<MovieReviewModel>(); 
         tagList = (List<MovieReviewModel>) movieReviewDao.getMovieReviewById(Long.valueOf(movie_id)); 

         if (tagList.size() > 0) { 

          Map<String, String> map = new TreeMap<String, String>(); 

          for (Iterator<MovieReviewModel> iterator = tagList.iterator();i<1;i++) { 

           MovieReviewModel masterModel = (MovieReviewModel) iterator.next(); 
           map.put(masterModel.getRatings(), 
             masterModel.getReview()); 
           model.addObject("typemap",map); 

          model.addObject("rating", masterModel.getRatings()); 
          model.addObject("review", masterModel.getReview());} 
         } 

        } 

       } catch (NullPointerException e) { 
        // TODO: handle exception 
        e.printStackTrace(); 
       } 

       model.addObject("id",Long.valueOf(movie_id)); 
       model.setViewName("admin_getmoviereview"); 
       return model; 

    } 

我也調試這個代碼和數據即將masterModel.getRatings();

這裏是JSP代碼:

$(document).ready(function() { 
        $("#moviename").keyup(function() { 
         if($('#moviename').val().length>1){ 
          $.ajax({ 
            url: "/cms/getmoviereviewread?term="+ $('#moviename').val(), 
            success: function(data) { 
             if(data.length>0){ 
              var str ='<ul style="list-style: none;">'; 
              for(var i=0;i<data.length;i++){ 
               var strtitle="'" +data[i].title + "'"; 
               str+='<li onclick="selectli('+strtitle+','+data[i].id+');">'+data[i].title+'</li>'; 
              } 
              $('#auto').html(str+'</ul>'); 
              $('#auto').show(800); 
             }else{ 
              $('#auto').hide(100); 
              if($('#moviename').val().length>1){ 
             $('#exist').html("Word Not exist!! <a class = 'clickpointer' onclick='addNewWord();'>Click Here</a> to Add"); 
              } 
            }} 
           }); 
         }else{ 
          $('#auto').hide(100); 
         } 
       }); 

     <script> 

     function selectli(listval,id){ 
     $('#moviename').val(listval); 
     //$('#rating').val(id); 
     $('#auto').hide(800); 
     //$('#exist').html("Word already exist!!"); 
     $.ajax({ 
      url : "/cms/getmoviereviewbyid/"+id, 
      type : "GET", 
      success : function(results) { 
       console.log("done"); 
      console.log(review); 
      console.log(results.review); 

      } 
     }); 

     } 
    </script> 
    <div class="row"> 
     <input type="text" class="int_srh" name="q" size="" id="moviename" 
      placeholder="Search movie" maxlength="120"> 
     <div id="div0"></div> 
    </div> 
    <div class="row"> 
     <input type="text" class="int_srh" name="q" size="" id="rating" 
      placeholder="Rating" maxlength="120"> 
    </div> 
    <div class="reviewdiv"> <p>Review/रिव्यु</p> 
      <textarea rows="10" cols="100" id="review" class="rev" ></textarea> 
    </div> 
+0

此外,我還將數據添加到地圖,以便有通過地圖獲取數據的方法 –

+0

您在控制檯中獲得了什麼?另外,你在哪裏調用javascript方法'selectli'? – VPK

+0

感謝回答我得到控制檯:做 VM87:13 VM87:14未定義 –

回答

0

返回新的ModelAndView( 「」「響應對象「,」這將是對象或你的模型對象「);

+0

也是在你的Ajax調用添加 數據類型:「JSON」, contentType:'application/json', –

相關問題