JavaEE学习 day08

今天,继续学习了JavaEE。继续做SSM图书管理系统项目。
ssm框架:
实现用户管理的分页操作:
service层:

@Service("userInfoService")
public class UserInfoServiceImpl implements IUserInfoService {
    @Autowired
    private IUserInfoDao userInfoDao;
 
    @Override
    public List<UserInfo> findAll(int page, int size) {
        PageHelper.startPage(page, size);
        return userInfoDao.findAll();
    }
 
    @Override
    public boolean login(UserInfo userInfo) {
        UserInfo user=userInfoDao.login(userInfo);
        if(user!=null){
            return true;
        }else{
            return false;
        }
    }
 
    @Override
    public void add(UserInfo userInfo) {
        userInfoDao.add(userInfo);
    }
 
    @Override
    public void delete(int id) {
        userInfoDao.delete(id);
    }
 
    @Override
    public void update(UserInfo userInfo) {
        userInfoDao.update(userInfo);
    }
 
    @Override
    public UserInfo query(int id) {
        return userInfoDao.query(id);
    }
}

controller层:

@RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(defaultValue = "1")int page,
                                @RequestParam(defaultValue = "5")int size){
 
        List<UserInfo> userInfos= userInfoService.findAll(page, size);
        PageInfo pageInfo=new PageInfo(userInfos);
        ModelAndView mv=new ModelAndView();
        mv.addObject("pageInfos",pageInfo);
        mv.setViewName("user-list");
        return mv;
    }

user-list的数据表操作:

<table id="dataList"
								class="table table-bordered table-striped table-hover dataTable">
								<thead>
									<tr>
										<th class="" style="padding-right: 0px"><input
											id="selall" type="checkbox" class="icheckbox_square-blue">
										</th>
										<th class="sorting_asc">ID</th>
										<th class="sorting_desc">用户名</th>
										<th class="sorting_asc sorting_asc_disabled">密码</th>
										<th class="text-center">操作</th>
									</tr>
								</thead>
								<tbody>
								    <c:forEach var="userInfo" items="${pageInfos.list}">
										<tr>
											<td><input name="ids" type="checkbox"></td>
											<td>${userInfo.id}</td>
											<td>${userInfo.username}</td>
											<td>${userInfo.password}</td>
											<td class="text-center">
												<a href="${pageContext.request.contextPath}/user/toUpdate.do?id=${userInfo.id}" class="btn bg-olive btn-xs">更新</a>
												<a href="${pageContext.request.contextPath}/user/delete.do?id=${userInfo.id}" class="btn bg-olive btn-xs">删除</a>
												<a href="#" class="btn bg-olive btn-xs">添加角色</a>
											</td>
										</tr>
									</c:forEach>
								</tbody>
								<!--
                            <tfoot>
                            <tr>
                            <th>Rendering engine</th>
                            <th>Browser</th>
                            <th>Platform(s)</th>
                            <th>Engine version</th>
                            <th>CSS grade</th>
                            </tr>
                            </tfoot>-->
							</table>
							<!--数据列表/-->
 
						</div>
						<!-- 数据表格 /-->
 
					</div>
					<!-- /.box-body -->
						<div class="box-tools pull-right">
							<ul class="pagination">
								<li><a href="${pageContext.request.contextPath}/user/findAll.do?page=1&size=5" aria-label="Previous">首页</a></li>
								<li><a href="${pageContext.request.contextPath}/user/findAll.do?page=${pageInfos.pageNum-1}&size=5">上一页</a></li>
								<c:forEach begin="1" end="${pageInfos.pages}" var="pageNum">
									<li>
										<a href="${pageContext.request.contextPath}/user/findAll.do?page=${pageNum}&size=5">${pageNum}</a>
									</li>
								</c:forEach>
 
 
								<li><a href="${pageContext.request.contextPath}/user/findAll.do?page=${pageInfos.pageNum+1}&size=5">下一页</a></li>
								<li><a href="${pageContext.request.contextPath}/user/findAll.do?page=${pageInfos.pages}&size=5" aria-label="Next">尾页</a></li>
							</ul>
						</div>
 
					</div>

aside.jsp中的操作:

<ul class="treeview-menu">
					<li id="system-setting">
						<a
						href="${pageContext.request.contextPath}/user/findAll.do?page=1&size=5"> <i
							class="fa fa-circle-o"></i> 用户管理
					</a>

pom.xml的dependency:

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.2</version>
    </dependency>

applicationContext.xml:中的声明:

 <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">mysql</prop>
                            <prop key="reasonable">true</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>

通过这些工作完成分页功能,让系统更加的友好。

你可能感兴趣的:(笔记)