遇到一个关于@Request Mapping跳转url的问题,不知怎么解决特来求助
控制器:
@Controller
@RequestMapping("/content")
public class ContentHandler {
@Autowired
private ContentServiceImpl contentService;
@RequestMapping(value="/detail/{articleId}")
public String detail(@PathVariable("articleId")Integer id,Model model) {
/*
obtainArticleByArticleId(int):根据文章Id得到的文章信息
*/
model.addAttribute("articleDetail", contentService.obtainArticleByArticleId(id));
return "Article/detail";
}
@RequestMapping("/show_articles/{userId}")
public String myArticles(@PathVariable("userId")Integer getId,
Map<String,Object> map) {
/*
obtainArticlesByAuthorId(int):根据用户Id得到的文章信息
*/
map.put("ArticleList", contentService.obtainArticlesByAuthorId(getId));
return "Article/show";
}
... ...
}
视图:
my_index.jsp
<%@page import="org.springframework.web.context.annotation.SessionScope"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>个人信息</title>
</head>
<body style="padding: 0px;">
<form>
<jsp:include page="/WEB-INF/views/Layout/layoutHeader.jsp"/>
<c:set var="userIdFromSession" value="${sessionScope.userId }"/>
<a href="create_article">写文章</a>
<a href="content/show_articles/${userIdFromSession}">我的文章</a>
<a href="my_info">我的信息</a>
</form>
</body>
</html>
show.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form>
<jsp:include page="/WEB-INF/views/Layout/layoutHeader.jsp"/>
<table style="border: solid gray 1px;text-align:center;">
<tr>
<td>标题</td>
<td>内容</td>
<td></td>
</tr>
<c:forEach items="${ArticleList}" var="info">
<tr>
<td><c:out value="${info.title}" /></td>
<td>
<c:choose>
<!-- 当文章内容的字符串长度大于32时截取文章内容 -->
<c:when test="${fn:length(info.content)<32}">
<c:out value="${info.content}" />
</c:when>
<c:otherwise>
<c:out value="${fn:substring(info.content,0,30)}..."/>
</c:otherwise>
</c:choose>
</td>
<td><a href="content/detail/${info.id}" target="_blank">detail</a></td>
</tr>
</c:forEach>
</table>
<hr>
</form>
</body>
</html>