SSM+EasyUI实现级联查询(模糊查询+时间段查询),帮助新手脱坑


 

1、实现效果

实现思路:后台获取前端搜索框的值,在查询所有的mapper中增加条件,重要的是用Map存放数据。


 

2、前端js

//查询事件----核心
        function searchScore() {
            $("#dg").datagrid('load', {
                "dormid": $("#s_dormid").val(),
                "scoretime": $("#s_scoretime").val(),
                "scoretime_end": $("#s_scoretime_end").val()
            });
        }
//重置事件
function reset() {
            $("#s_dormid").textbox('setValue', "");
            $("#s_scoretime").datetimebox('setValue', "");
            $("#s_scoretime_end").datetimebox('setValue', "");
        }

 

3、前端页面

评分日期实现时间段查询(开始日期-截至日期),所以在实体类model增加一个字段存放截至日期scretime_end

  宿舍: 
         评分日期:  -
        

        查询
        重置

 

 4、medel

public class Score {
    private Integer id;
    private String dormid;
    private String scoretime;
    private String scoretime_end;
//getter和setter
}

 

 5、dao、service

public interface ScoreDao {

    List find(Map map);
}

public interface ScoreService {

    List find(Map map);
}

 

6、Impl

@Service("ScoreService")
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreDao scoreDao;
    @Override
    public List find(Map map) {
        return scoreDao.find(map);
    }
}

 

7、json数据工具类

public class ResponseUtil {
    public static void write(HttpServletResponse response, Object object) throws Exception {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println(object);
        out.flush();
        out.close();
    }
}

8、controller

 @RequestMapping("/list")
    public String list(Score s_score, HttpServletResponse res) throws Exception {
        Map map = new HashMap();
        map.put("dormid", StringUtil.formatLike(s_score.getDormid()));
        map.put("scoretime",s_score.getScoretime());
        map.put("scoretime_end",s_score.getScoretime_end());
        List visitorList = scoreService.find(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(visitorList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(res, result);
        return null;

9、模糊查询工具类

public static String formatLike(String str){
        if(isNotEmpty(str)){
            return "%"+str+"%";
        }else{
            return null;
        }
    }

10、mapper

查询框都为空的时候默认查询所有显示出来,输入内容即为条件搜索

 
        
        
        
    

代码对您有帮助的话记得点个赞哦! 

 

你可能感兴趣的:(SSM+EasyUI实现级联查询(模糊查询+时间段查询),帮助新手脱坑)