public interface ZxwxKFJSDWRepository extends JpaRepository<ZxwxKFJSDW, String>,
PagingAndSortingRepository<ZxwxKFJSDW, String>{
//插入数据
public ZxwxKFJSDW save(ZxwxKFJSDW jsdw);
//更新数据
public ZxwxKFJSDW saveAndFlush(ZxwxKFJSDW jsdw);
//删除数据
@Modifying(clearAutomatically = true)
public void delete(String dwm);
//按照名字来查询
public ZxwxKFJSDW findByDwm(String dwm);
/**
* 注意:在做分页查询的时候,不需要在这个借口定义方法了。可以直接调用
*/
//public List<ZxwxKFJSDW> findAll();
}
control中分页查询
@RequestMapping(value="/kfjsdwlisthtml")
public ModelAndView jsdwdlist(@RequestParam(value="pageNumberstr",required=false)
String pageNumberstr){
if(pageNumberstr==null ||"".equals(pageNumberstr)){
pageNumberstr="0";
}
int pageNumber = Integer.parseInt(pageNumberstr);
int pageSize = 5;
ModelAndView modelAndView=new ModelAndView();
PageRequest pageRequest=new PageRequest(pageNumber, pageSize,null);
Page<ZxwxKFJSDW> jsdwPage = jsdwRepos.findAll(pageRequest);
List<ZxwxKFJSDW> jsdwPagelist=jsdwPage.getContent();
modelAndView.addObject("jsdwlist",jsdwPagelist);
//总记录数
modelAndView.addObject("totalPageNumber",jsdwPage.getTotalElements());
//当前页
modelAndView.addObject("pageNumberstr",pageNumber);
//每页多少行
modelAndView.addObject("pagesize",pageSize);
//总页数
modelAndView.addObject("TotalPages",jsdwPage.getTotalPages()-1);
modelAndView.setViewName("/jcxx/jsdwList");
return modelAndView;
}
页面:
<tr th:each="jsdw:${jsdwlist}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.dwm}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.jgcode}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.lxr}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.tel}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.szxzqn}">
<td align="center" bgcolor="#EFFBFE" th:text="${jsdw.szxzqm}">
<td align="center" bgcolor="#EFFBFE">
<a th:href="@{'/kfjwdw/updatehtml?dwm='+${jsdw.dwm}}">更新</a>|
<a th:href="@{'/kfjwdw/delete?dwm='+${jsdw.dwm}}">删除</a>
</td>
</tr>
<div width="80%" align="center" bgcolor="#EFFBFE">
<div align="center" bgcolor="#EFFBFE">
<a th:href="@{/kfjwdw/kfjsdwlisthtml?pageNumberstr=0}">首页</a>
<a th:href="@{'/kfjwdw/kfjsdwlisthtml?pageNumberstr='+*{pageNumberstr-1}}">上一页</a>
<a th:href="@{'/kfjwdw/kfjsdwlisthtml?pageNumberstr='+*{pageNumberstr+1}}">下一页</a>
<a th:href="@{'/kfjwdw/kfjsdwlisthtml?pageNumberstr='+*{TotalPages}}">尾页</a>
</div>
</div>