SpringBoot2.x | 分页插件PageHelper

pom.xml


<dependency>
	<groupId>com.github.pagehelpergroupId>
	<artifactId>pagehelper-spring-boot-starterartifactId>
	<version>1.2.9version>
dependency>

appliction.properties

# Pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

服务层接口实现,如VipServiceImpl.java

/**
 * 获取所有的会员信息
 * @param page 页码
 * @param rows 当前页会员数
 * @return vips
 */
@Overrid
public List<Vip> getAll(Integer page, Integer rows) {
    // PageHelper分页信息
    PageHelper.startPage(page, rows);
    // 获取所有会员信息
    VipExample vipExample = new VipExample();
    // 通过Criteria构造查询条件
    VipExample.Criteria criteria = vipExample.createCriteria();
    criteria.andVipIdIsNotNull();
    List<Vip> vips = vipMapper.selectByExample(vipExample);
    return vips;
}

MemberController.java

import com.bookstore.entity.Vip;
import com.bookstore.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 

会员相关页面控制层

* =================== * @author noTalent * @version 1.0 */
@Controller public class MemberController { @Autowired private VipService vipService; /** * 会员列表路由 * @return member-list.html */ @RequestMapping(value = "/member-list") public String memberList(Model model, @RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "10") Integer size) { List<Vip> vips = vipService.getAll(page, size); if (vips != null && vips.size() > 0) { model.addAttribute("vips", vips); } return "member-list"; } }

Thymeleaf

<tr th:each="vip : ${vips}">
   <td>
   <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">i>div>
   td>
   <td th:text="${vip.getVipId()}">td>
   <td th:text="${vip.getVipUsername()}">td>
   <td th:text="${vip.getVipPassword()}">td>
   <td th:text="${vip.getVipNickname()}">td>
   <td th:text="${vip.getVipGender()}">td>
   <td>td>
   <td th:text="${vip.getVipPhone()}">td>
   <td th:text="${vip.getVipEmail()}">td>
   <td th:text="${vip.getVipBirthday()}">td>
   <td th:text="${vip.getVipLocation()}">td>
   <td th:text="${vip.getVipCreateTime()}">td>
   <td class="td-status">
      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用span>td>
   <td>
      <a title="编辑"  onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">
         <i class="layui-icon">i>
      a>
      <a onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
         <i class="layui-icon">i>
      a>
    td> 
tr>

你可能感兴趣的:(SpringBoot)