У меня есть метод GET в js
$(".btn-sm").click(function() {
$.ajax({
url: '/check_rating/'+this.value,
type: 'GET',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});
});
URL-адрес такой, как этот / check_rating / 1 .Контроллер
@RequestMapping(value = "/check_rating/{id}",method = RequestMethod.GET)
public String check_rating(@PathVariable("id")Long id, RedirectAttributes redirectAttributes){
List<Rating>rating = ratingService.findAllRatingsByIdStudentAndStageOfApproveGreaterThan(id,0);
redirectAttributes.addFlashAttribute("rating",rating);
return "redirect:/students_rating";
}
@RequestMapping(value = "/students_rating",method = RequestMethod.GET)
public String student_rating(@ModelAttribute("rating") List<Rating>rating, ModelMap model){
model.addAttribute("rating",rating);
return "students_rating";
}
}
Мне нужно перенаправить в / student_rating, но после отправки метода get с помощью url / check_rating / 1 я все еще остаюсь на той же странице, и перенаправление теперь работает, но на консоли у меня есть журнал такой
MODEL = {rating=[student_rating.entity.Rating@7856e7f, student_rating.entity.Rating@6a369ebf, student_rating.entity.Rating@7ed68627], org.springframework.validation.BindingResult.rating=org.springframework.validation.BeanPropertyBindingResult: 0 errors}
o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'students_rating'; URL [/pages/students_rating.jsp]] in DispatcherServlet with name 'dispatcher'
DEBUG o.s.web.servlet.view.JstlView - Added model object 'rating' of type [java.util.ArrayList] to request in view with name 'students_rating'
o.s.web.servlet.view.JstlView - Added model object 'org.springframework.validation.BindingResult.rating' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'students_rating'
o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'requestDataValueProcessor'
o.s.web.servlet.view.JstlView - Forwarding to resource [/pages/students_rating.jsp] in InternalResourceView 'students_rating'
o.s.web.servlet.DispatcherServlet - Successfully completed request
o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
Students_rating.jsp
<tbody id="tBody">
<c:forEach items="${requestScope.rating}" var="rating">
<tr><td class="column"><c:out value="${rating.id}"></c:out></td><td><c:out value="${rating.date}"></c:out></td><td><c:out value="${rating.score}"></c:out></td></tr>
</c:forEach>
</tbody>