我正在尝试将数据从控制器类传递给jsp但是当我在服务器上运行它时显示空值但我的id是正确的并且我的查询也返回了期望结果但是当我从jsp获取它时它不显示任何价值。控制台中的错误是500内部服务器错误。 这是我的控制器代码:
@RequestMapping(value = "getmoviereviewbyid/{id}", method = RequestMethod.GET)
public ModelAndView getMovieReviewByID(@PathVariable("id") String id) throws IOException {
ModelAndView
model = new ModelAndView();
MovieReviewModel mrm=new MovieReviewModel();
mrm=movieReviewDao.getMovieReviewById(Long.valueOf(id));
model.addObject("review", mrm.getReview());
model.addObject("movierating", mrm.getRatings());
model.setViewName("getmoviereviewbyid");
return model;
}
这是jsp代码部分:
function selectli(listval,id){
$('#moviename').val(listval);
$('#movierating').val(id);
$('#auto').hide(800);
$('#exist').html("Word already exist!!");
$.ajax({
url : "/cms/getmoviereviewbyid/"
+ id,
type : "GET",
success : function(results) {
$('#moviereview').val(results.review);
}
});
}
这是我的道具:
@Override
public MovieReviewModel getMovieReviewById(Long id) {
return (MovieReviewModel) getHibernateTemplate().find("from MovieReviewModel where movie_id="+ id);
}
以下是获取ID的代码
@RequestMapping(value = "admin_getmoviereview/{name}", method = RequestMethod.GET)
public ModelAndView getMovieReview(
@PathVariable("name") String name)
throws IOException {
ModelAndView model = new ModelAndView();
try {
if (name != null) {
List<MovieModel> tagList = new ArrayList<MovieModel>();
tagList = (List<MovieModel>) movieReviewDao.getMovieReviewByMovie(name);
//.findGallery(15441);
if (tagList.size() > 0) {
Map<String, Long> map = new TreeMap<String, Long>();
for (Iterator<MovieModel> iterator = tagList.iterator(); iterator
.hasNext();) {
MovieModel masterModel = (MovieModel) iterator.next();
map.put(masterModel.getName(),
(long) masterModel.getId());
}
model.addObject("typemap", map);
}
}
} catch (NullPointerException e) {
// TODO: handle exception
e.printStackTrace();
}
model.addObject("name", name);
model.setViewName("admin_getmoviereview");
return model;
}
这是jsp
<script>
$(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);
$('#movierating').val(id);
$('#auto').hide(800);
$('#exist').html("Word already exist!!");
$.ajax({
url : "/cms/getmoviereviewbyid/"
+ id,
type : "GET",
success : function(results) {
$('#moviereview').val(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="movierating"
placeholder="Rating" maxlength="120">
</div>
<div class="row">
<input type="text" class="int_srh" name="q" size="" id="moviereview"
placeholder="Review" maxlength="120">
</div>
<div id="auto"></div>
<div id="meaning"></div>
<script type="text/javascript">
$().ready(function() {
$('#dialog').jqm();
});
</script>
[Object]
jquery.min.js:4 GET http://localhost:8080/cms/getmoviereviewbyid/150 500 (Internal Server Error)jquery.min.js:4 m.ajaxTransport.sendjquery.min.js:4 m.extend.ajaxVM238:8 selectliVM237:37 $.ajax.successjquery.min.js:2 m.Callbacks.jjquery.min.js:2 m.Callbacks.k.fireWithjquery.min.js:4 xjquery.min.js:4 m.ajaxTransport.send.b