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"; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。