赞
踩
package com.july.community.dto;
import lombok.Data;
@Data
public class QuestionQueryDTO {
private String search;
private Integer page;
private Integer size;
}
QuestionQueryDTO questionQueryDTO = new QuestionQueryDTO();
questionQueryDTO.setSearch(search);
Integer totalCount = questionExtMapper.countBySearch(questionQueryDTO);
...
questionQueryDTO.setSize(size);
questionQueryDTO.setPage(offset);
List<Question> questions = questionExtMapper.selectBySearchWithRowbounds(questionQueryDTO);//该list存从数据库中查到的question对象
Integer countBySearch(QuestionQueryDTO questionQueryDTO);
List<Question> selectBySearchWithRowbounds(QuestionQueryDTO questionQueryDTO);
<select id="countBySearch" parameterType="com.july.community.dto.QuestionQueryDTO" resultType="java.lang.Integer"> select count(*) from tbl_question <where> <if test="search != null"> and title regexp #{search} </if> </where> </select> <select id="selectBySearchWithRowbounds" parameterType="com.july.community.dto.QuestionQueryDTO" resultMap="BaseResultMap"> select * from tbl_question <where> <if test="search != null"> and title regexp #{search} </if> </where> order by time_modified desc limit #{offset},#{size} </select>
<form class="navbar-form navbar-left" name="search" action="/" method="get">
<div class="form-group">
<input type="text" class="form-control" placeholder="搜索问题">
</div>
<button type="submit" class="btn btn-default">搜索</button>
</form>
model.addAttribute("search",search);
分页:index.html
<!--分页标签--> <nav aria-label="Page navigation"> <ul class="pagination"> <li th:if="${pagination.showFirstPage}"> <a href="@{/(page=1,search=${search})}" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li th:if="${pagination.showPrevious}"> <a th:href="@{/(page=${pagination.page - 1},search=${search})}" aria-label="Previous"> <span aria-hidden="true"><</span> </a> </li> <li th:each="page : ${pagination.pages}" th:class="${pagination.page == page} ? 'active' : ''"> <a th:href="@{/(page=${page},search=${search})}" th:text="${page}" ></a> </li> <li th:if="${pagination.showNext}"> <a th:href="@{/(page=${pagination.page + 1},search=${search})}" aria-label="Next"> <span aria-hidden="true">></span> </a> </li> <li th:if="${pagination.showEndPage}"> <a th:href="@{/(page=${pagination.totalPage},search=${search})}" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。