SSM+boostrap table实现模糊搜索

List<Menu> selectByExampleAll(String search);

<select id="selectByExampleAll" parameterType="com.tor.bean.MenuExample" resultMap="BaseResultMap">
   SELECT *
   FROM menu_table
   WHERE menu_kind LIKE CONCAT(CONCAT('%', #{search}), '%')
         OR menu_name LIKE CONCAT(CONCAT('%', #{search}), '%')
         OR menu_id LIKE CONCAT(CONCAT('%', #{search}), '%')
         OR menu_price LIKE CONCAT(CONCAT('%', #{search}), '%')
         OR menu_tupian LIKE CONCAT(CONCAT('%', #{search}), '%')
  </select>


<table id="mytab" class="table table-hover">


</table><body>

<div class="col-md-5">
    <label class="col-sm-2 control-label" style="text-align: right; margin-top:5px">模糊搜索:</label>
    <div class="col-sm-2">
        <input type="text" class="form-control" name="Name" id="search_name"/>
    </div>
    <div class="col-sm-1">
        <button class="btn btn-primary" id="search_btn">查询</button>
    </div>
</div>
</body>
<script type="text/javascript">

    var t=$('#mytab').bootstrapTable({
        method: 'post',
        search:true,//启用搜索框
        paginationLoop:false,//默认true,分页条无限循环
        clickToSelect:true,
        contentType: "application/x-www-form-urlencoded",//当请求方法为post的时候,必须要有!!!!
        url:"menuController/menuShow",//请求路径
        striped: true, //是否显示行间隔色
        pageNumber: 1, //初始化加载第一页
        pagination:true,//是否分页
        sidePagination:'server',//server:服务器端分页|client:前端分页
        pageSize:5,//单页记录数
        pageList:[5,10,20,30],//可选择单页记录数
        showRefresh:true,//刷新按钮
        idField: "menuId",//指定主键列
        paginationPreText: '‹',//指定分页条中上一页按钮的图标或文字,这里是<
        paginationNextText: '›',//指定分页条中下一页按钮的图标或文字,这里是>
        queryParams : function (params) {//上传服务器的参数
            var temp = {                    //如果是在服务器端实现分页,limit、offset这两个参数是必须的
                limit : params.limit,      // 每页显示数量
                offset : params.offset,     // SQL语句起始索引
                page: (params.offset / params.limit) + 1,   //当前页码*/
                search:$('#search_name').val(),
            };
            return temp;
        },
        columns:[
            {
                title:'全选',
                field:'select',
                //复选框
                checkbox:true,
                width:25,
                align:'center',
                valign:'middle'
            },
            {
                title:'登录名',
                field:'menuId',
                sortable:true
            },
            {
                title:'姓名',
                field:'menuName',
                sortable:true
            },
            {
                title:'手机号',
                field:'menuPrice',
            },
            {
                title:'性别',
                field:'menuTupian',
                /*formatter: formatSex,//对返回的数据进行处理再显示*/   //判断男女
            },
            {
                 title:'手机号',
                  field:'menuKind',
             },
            {
                title: '操作',
                field: 'userId',
                align: 'center',
                formatter: function (value, row, index) {//自定义显示,这三个参数分别是:value该行的属性,row该行记录,index该行下标
                    return '<a href="#" mce_href="#" οnclick="edit(\'' + row.userId + '\')">操作</a> ';
                }
            }
        ]
    })

    //value代表该列的值,row代表当前对象
    function formatSex(value,row,index){
        return value == 1 ? "男" : "女";
        //或者 return row.sex == 1 ? "男" : "女";
    }

    //查询按钮事件
    $('#search_btn').click(function(){
        $('#mytab').bootstrapTable('refresh', {url:"menuController/menuShow"});
    })
@RequestMapping(value = "/menuShow")
    @ResponseBody
    public PageHelper<Menu> getUserListPage(Menu menu, HttpServletRequest request) {
        PageHelper<Menu> pageHelper = new PageHelper<Menu>();
        // 统计总记录数
        Integer total = menuService.getAll(menu.getSearch()).size();
        pageHelper.setTotal(total);
        // 查询当前页实体对象
        List<Menu> list = menuService.getAll(menu.getSearch());
        pageHelper.setRows(list);
        System.out.println(menu.getSearch());
        return pageHelper;
    }

public class PageHelper<T> {  
    //实体类集合  
    private List<T> rows = new ArrayList<T>();  
    //数据总条数  
    private int total;  
  
    public PageHelper() {  
        super();  
    }  
  
    public List<T> getRows() {  
        return rows;  
    }  
  
    public void setRows(List<T> rows) {  
        this.rows = rows;  
    }  
  
    public int getTotal() {  
        return total;  
    }  
  
    public void setTotal(int total) {  
        this.total = total;  
    }  
  
}  

public class Menu extends Page {
    private Integer menuId;

    private String menuName;

    private Integer menuPrice;

    private String menuTupian;

    private String menuKind;

    public Integer getMenuId() {
        return menuId;
    }

    public void setMenuId(Integer menuId) {
        this.menuId = menuId;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName == null ? null : menuName.trim();
    }

    public Integer getMenuPrice() {
        return menuPrice;
    }

    public void setMenuPrice(Integer menuPrice) {
        this.menuPrice = menuPrice;
    }

    public String getMenuTupian() {
        return menuTupian;
    }

    public void setMenuTupian(String menuTupian) {
        this.menuTupian = menuTupian == null ? null : menuTupian.trim();
    }

    public String getMenuKind() {
        return menuKind;
    }

    public void setMenuKind(String menuKind) {
        this.menuKind = menuKind == null ? null : menuKind.trim();
    }


public class Page {
    //每页显示数量  
    private int limit;  
    //页码  
    private int page;  
    //sql语句起始索引  
    private int offset;

    private String search;

    public int getLimit() {  
        return limit;  
    }  
    public void setLimit(int limit) {  
        this.limit = limit;  
    }  
    public int getPage() {  
        return page;  
    }  
    public void setPage(int page) {  
        this.page = page;  
    }  
    public int getOffset() {  
        return offset;  
    }  
    public void setOffset(int offset) {  
        this.offset = offset;  
    }
    public String getSearch() {
        return search;
    }
    public void setSearch(String search) {
        this.search = search;
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值