在SSM框架搭建之maven方式(二)基礎(chǔ)上進(jìn)一步做以下修改
創(chuàng)新互聯(lián)成都企業(yè)網(wǎng)站建設(shè)服務(wù),提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)網(wǎng)站開發(fā),網(wǎng)站定制,建網(wǎng)站,網(wǎng)站搭建,網(wǎng)站設(shè)計(jì),自適應(yīng)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì)師打造企業(yè)風(fēng)格網(wǎng)站,提供周到的售前咨詢和貼心的售后服務(wù)。歡迎咨詢做網(wǎng)站需要多少錢:028-86922220
pom.xml添加如下代碼
com.github.pagehelper
pagehelper
5.1.2
spring-mybatis.xml的id標(biāo)簽為sqlSessionFactory節(jié)點(diǎn)中添加如下內(nèi)容
helperDialect=MySQL
reasonable=true
autoRuntimeDialect=true
將UserController.java中的內(nèi)容改寫為如下代碼
package com.lymn.it.controller;
import java.util.List;
import org.apache.log4j.Logger;
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 com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lymn.it.model.User;
import com.lymn.it.service.UserService;
@Controller
public class UserController {
@Autowired
UserService userService;
Logger logger=Logger.getLogger(UserController.class);
@RequestMapping(value="/user")
public String user(@RequestParam(defaultValue="1",required=true,value="pageNo") Integer pageNo,Model model) {
logger.info("查詢所有用戶數(shù)據(jù)");
PageHelper.startPage(pageNo, 5);
List userList = userService.getAllUsers();
PageInfo pageInfo=new PageInfo(userList);
model.addAttribute("userList", userList);
model.addAttribute("pageInfo", pageInfo);
logger.info("查詢完畢,返回頁面");
return "user";
}
}
將user.jsp中的內(nèi)容改寫為如下代碼
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
User
userid
username
password
email
${user.userid}
${user.username}
${user.password}
${user.email}
當(dāng)前 ${pageInfo.pageNum }頁,總${pageInfo.pages }
頁,總 ${pageInfo.total } 條記錄
訪問如下圖所示表示成功