将单个模型属性传递给JSP

时间:2015-09-01 09:29:04

标签: jsp spring-mvc

我正在Spring MVC中创建一个内容管理系统,并尝试从我的数据库中进行审核。一切正常,但当我点击电影名称时,我想将评论值传递给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>

1 个答案:

答案 0 :(得分:0)

返回新的ModelAndView(&#34;&#34;,&#34; responseObject&#34;,&#34;这将是地图对象或您的模型对象&#34;);