jsp文件头
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
web资源路径问题
是不是感觉写${pageContext.request.contextpath}/很长,比较费劲,有没有什么简写的方法呢?
现提供两种解决办法
方法一
<%pageContext.setAttribute("appPath",request.getcontextpath()); %>
- 取出的方式为:${appPath}/
<link rel="stylesheet" type="text/css" href="${appPath }/static/H-ui/css/H-ui.min.css" />
方式二
<%string appPath = request.getcontextpath()+"/"; %>
- 取出的方式为:<%=appPath%>
<link rel="stylesheet" type="text/css" href="<%=appPath %>static/H-ui/css/H-ui.min.css" />
注意:HttpServletRequest request.getcontextpath()
得到的web项目路径是不带/
的,例如/ssm-crm
pageHelper分页插件使用
<!-- pageHelper分页插件注册 --> <plugins> <plugin interceptor="com.github.pageHelper.PageInterceptor"> <!-- 分页参数合理化 --> <property name="resonable" value="true" /> </plugin> </plugins>
- Controller中使用方式
@RequestMapping(value = "/custs") public String getCusts(@RequestParam(value = "pn",defaultValue = "1") Integer pn,Model model) { // 调用pageHelper,启用分页查询,10为每页显示的记录数,也可以从页面传入,此时需要增加方法的参数 @RequestParam(value = "limit",defaultValue = "10") // 这行代码一定要放在第一句,否则不能进行分页查询 pageHelper.startPage(pn,10); List<Customer> list = customerService.getAll(); // 5为每页连续显示的页数 PageInfo<Customer> pageInfo = new PageInfo<>(list,5); model.addAttribute("pageInfo",pageInfo); return "customer-list"; }