私はSpring MVC &で新しくなっています。 http://localhost:8088/postListを開くことができますが、http://localhost:8088/post/1を開くとWhitelabel Error Pageエラーが発生します。私は間違いを見つけることができません。あなたはそれを言うことができますか?Spring MVCはInternalResourceViewResolverビュー名が間違っているため404を返します
マイプロジェクト構造
マイInternalResourceViewer:
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
マイコントローラー:
@Controller
@RequestMapping("/")
public class PostController
{
@Autowired
PostService postService;
@RequestMapping(value="/post/{id}", method=RequestMethod.GET)
public ModelAndView list(@PathVariable("id") int id){
ModelAndView mav=new ModelAndView("post");
Post postItem=postService.getPostById(id);
mav.addObject("postItem",postItem);
mav.addObject("postItem",postItem);
return mav;
}
@RequestMapping(value="/postList", method=RequestMethod.GET)
public ModelAndView postlist(){
ModelAndView mav=new ModelAndView("postList");
mav.addObject("postList",postService.listPosts());
return mav;
}
}
マイPostList:
私のポストの閲覧ページ:
マイpostList.jspのタグライブラリと内容:
<div class="row"> <c:if test="${not empty postList}"> <c:forEach var="postItem" items="${postList}"> <div class="col-lg-8"> <h1><a href="<c:url value='/post/${postItem.id}' />">${postItem.header}</a></h1> <p class="lead"> by <a href="#">${postItem.user_id}</a> </p> <p><span class="glyphicon glyphicon-time"></span>${postItem.upddate}</p> <hr> </div> </c:forEach> </c:if>
リンクを含む 'postList.jsp'コンテンツを表示します。 –