SpringMVC 过滤器 以及注解的一些应用

继承自 OncePerRequestFilter 接口。

获取用户的IP:  request.getLocalAddr().toString();

获取用户Session  request.getSession().getAttribute("adminUser")

ModelAndView view=new ModelAndView();

view.setViewName("admin/index");

view.addObject("error", "用户名或密码错误,请重试!");  在前台可以直接取得 error   用EL表达式就可以     ${error}

@ModelAttribute("admin")Admin admin   其实有没有@ModelAttribute("admin")无所谓   在前台的 name 要和 admin的属性相对应 

<input type="password" class="form-control" id="password" name="password" placeholder="密码">

href="list/校友会.html"

@RequestMapping(value = "/list/{type}.html", method = RequestMethod.GET)

@PathVariable("type")String type

jstl标签:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

  <c:forEach var="topnews" varStatus="status" items="${allNewsList}" begin="0" end="0">

    <a href="news.html?id=${topnews.id}" target="_blank">

   </c:forEach>

                  <c:choose>
                    <c:when test="${newstype == 'allnews'}">   
                     全部新闻
                    </c:when>
                    <c:when test="${newstype == '通知'}">   
                     通知公告
                    </c:when>
                    <c:otherwise>
                    ${newstype }
                    </c:otherwise>
                 </c:choose>

原文地址:https://www.cnblogs.com/dobestself-994395/p/4378555.html