o_6108895 2017-11-25 16:54 采纳率: 0%
浏览 2068

SpringMVC@RequestMapping返回url问题

遇到一个关于@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>
  • 写回答

2条回答 默认 最新

  • COCO_AS 2017-11-26 00:42
    关注

    <a href="content/detail/${info.id}" target="_blank">detail</a>
    

    改成

    <a href="../../content/detail/${info.id}" target="_blank">detail</a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制