ssm+easyui多个查询框模糊查询

easyui 是一个基于 jQuery 的框架,集成了各种用户界面插件。

easyui 提供建立现代化的具有交互性的 javascript 应用的必要的功能。

使用 easyui,您不需要写太多 javascript 代码,一般情况下您只需要使用一些 html 标记来定义用户界面。

HTML 网页的完整框架。

easyui 节省了开发产品的时间和规模。

easyui 非常简单,但是功能非常强大。

下面写的那个模糊查询就基于easyui来写。

工具用的是eclipse,Navicat

首先是布局,在jsp页面。

//搜索按钮监听 
$("#search-btn").click(function(){
	//学院下拉框
	var academyid = $("#search-academy").combobox('getValue');
	//专业下拉框
	var specialityid = $("#search-speciality").combobox('getValue');
	//年级下拉框
	var gradeid = $("#search-grade").combobox('getValue');
	//班级名称
	var option = {classname:$("#search-name").val()};
	if (academyid != -1) {
		option.academyid = academyid;
	}
	if (specialityid != -1) {
		option.specialityid = specialityid;
	}
	if (gradeid != -1) {
		option.gradeid = gradeid;
	}
		//重载
	$('#data-datagrid').datagrid('reload',option);
});

下载mybatis.generator.gui生成器,然后生成po、dao、mapper.xml文件

Po层就是表的字段,这里就不写出来了

Dao层:自动生成的可以不用它生成的方法,用自己写的也可以

package com.school.dao.base;
import com.school.po.base.SysClass;
import com.school.po.base.SysClassExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

/**
 * 班级dao
 */
@Repository
public interface SysClassMapper {
    long countByExample(SysClassExample example);
    int deleteByExample(SysClassExample example);
    int deleteByPrimaryKey(Integer classid);
    int insert(SysClass record);
    int insertSelective(SysClass record);
    List<SysClass> selectByExample(SysClassExample example);
    SysClass selectByPrimaryKey(Integer classid);
    int updateByExampleSelective(@Param("record") SysClass record, @Param("example") SysClassExample example);
    int updateByExample(@Param("record") SysClass record, @Param("example") SysClassExample example);
    int updateByPrimaryKeySelective(SysClass record);
    int updateByPrimaryKey(SysClass record);
    //搜索
	SysClass findByName(String classname);
}

Service层:

package com.school.service.base;

import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.school.po.base.SysClass;

/**
 * 班级信息service
 */
@Service
public interface ClassService {
    public List<SysClass> findList(Map<String, Object> queryMap);//班级下拉框
    public Integer getTotal(Map<String, Object> queryMap);//查询总条数
    public SysClass findByName(String classname);//根据班级名称查询信息
}

Impl层:

package com.school.service.impl.base;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.school.dao.base.SysClassMapper;
import com.school.po.base.SysClass;
import com.school.service.base.ClassService;

/**
 * 班级实现类
 */
@Service  //service层注解
public class ClassServiceImpl implements ClassService{

    @Autowired
    private SysClassMapper classDao;

    @Override
    public List<SysClass> findList(Map<String, Object> queryMap) {
        // 班级下拉框
        return classDao.findList(queryMap);
    }

    @Override
    public Integer getTotal(Map<String, Object> queryMap) {
        // 总条数
        return classDao.getTotal(queryMap);
    }

    @Override
    public SysClass findByName(String classname) {
    // 跟班级名称搜索查询
        return classDao.findByName(classname);
    }
}

Mapper.xml层:

 

Controller层:

package com.school.controller.base;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.school.page.Page;//封装的工具类
import com.school.po.base.SysClass;
import com.school.service.base.AcademyService;
import com.school.service.base.ClassService;
import com.school.service.base.GradeService;
import com.school.service.base.SpecialtyService;

/**
 * 基础--班级管理
 */
@RequestMapping("/base/class")
@Controller
public class ClassController {

    @Autowired
    private ClassService classService;
    @Autowired
    private AcademyService academyService ;
    @Autowired
    private SpecialtyService specialtyService;
    @Autowired
    private GradeService gradeService;

    /**
     * 班级管理页面+下拉框绑定
     * @param model
     * @return
     */
    @RequestMapping(value = "/classlist",method = RequestMethod.GET)
    public ModelAndView classlist(ModelAndView model) {
        model.setViewName("base/classlist");
        Map<String, Object> queryMap = new HashMap<String, Object>();
        queryMap.put("offset", 0);//起始条数
        //学院下拉框
        model.addObject("academyList",academyService.findList(queryMap));
        //专业下拉框
        model.addObject("specialityList",specialtyService.findList(queryMap));
        //年级下拉框
        model.addObject("gradeList",gradeService.findList(queryMap));
        return model;
    }

    /**
     * 模糊分页查询
     * @param page
     * @param name
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getList(Page page,
            @RequestParam(name="classname",defaultValue = "")String name,
            @RequestParam(name="academyid",required = false) Long academyid,
            @RequestParam(name="specialityid",required = false) Long specialityid,
            @RequestParam(name="gradeid",required = false) Long gradeid){

        Map<String, Object> ret = new HashMap<String, Object>();
        Map<String, Object> queryMap = new HashMap<String, Object>();
        queryMap.put("classname", name);
        queryMap.put("academyid", academyid);
        queryMap.put("specialityid", specialityid);
        queryMap.put("gradeid", gradeid);

        //学院下拉框绑定查询
        if (academyid != null && academyid.longValue() != -1) {
            queryMap.put("academyid", academyid);
        }
        //专业下拉框绑定查询
        if (specialityid != null && specialityid.longValue() != -1) {
            queryMap.put("specialityid", specialityid);
        }
        //年级下拉框绑定查询
        if (gradeid != null && gradeid.longValue() != -1) {
            queryMap.put("gradeid", gradeid);
        }
        queryMap.put("offset", page.getOffset());
        queryMap.put("pageSize", page.getRows());
        ret.put("rows", classService.findList(queryMap));
        ret.put("total", classService.getTotal(queryMap));
        return ret;
    }

}

封装工具类:page

package com.school.page;

import org.springframework.stereotype.Component;

/**
 * 分页基本信息
*/
@Component
public class Page {

    private int page = 1;//当前页码
    private int rows;//每页显示数量
    private int offset;//对应数据库中的偏移量

    public int getPage() {
        return page;
    }
    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }
    public void setRows(int rows) {
        this.rows = rows;
    }

    //分页
    public int getOffset() {
        this.offset = (page - 1) * rows;
        return offset;
    }
    public void setOffset(int offset) {
        this.offset = offset;
    }
}

效果:无论在哪个框输入值都能查询出相对应的消息

 

或者全部一起搜索也行

以上就是模糊搜索

注:根据网上视频学习

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值