EasyUI验证扩展

问题描述:

如上所示:当用户添加信息时,必须保证一个队伍一天只能有一条数据。所以在选择了报表日期的时候必须查询数据库里面当前队伍这一天的数据是否存在。如果不存在,即当前日期队伍没有数据,就可以进行数据添加;否则不能再进行添加。

前台页面如上所示,就是一个table,data-option属性里面写了自己的验证:validType:'reportDate'。而这个验证我们写在界面的js里。

//验证扩展  日报验证(每个队伍一天只有一条日报)
$.extend($.fn.validatebox.defaults.rules, {
	reportDate : {
        validator : function(value, param) {
        	 var response = $.ajax({
                 url: '/dh/rpt/fa/day/team/getDayTeam',
                 data: {reportDate:value},
                 async: false,
                 type: 'get'
             }).responseText;
        	  var obj = JSON.parse(response);
              if (obj.length==0){
                  return true;
              } else {
                  return false;
              }
        },
        message : '该日期的日报已经存在'
    }
});

  在这个js里面主要是为了获取到我们填写的日期,并把它传到后台的controller的map里。后台进行查询,返回查询到的数据的条数。

/**
 * 验证(每个小队每天只能有一个日报)
 * @param user
 * @return queryAll
 */
@RequestMapping(value="/getDayTeam",method= {RequestMethod.GET})
@ResponseBody
public List<Map<String, Object>> getDayTeam( @RequestParam Map<String, Object> map, User user) {
	map.put("orgCode", user.getOrg().getOrgCode());
	List<Map<String, Object>> queryAll = queryService.queryAll("DhRptFaDayTeamMapper","selectDayTeamByDateAndOrgCode", map);
	return queryAll;
}

  在后台的controller里面,通过获取到前台传递的日期进行查询queryAll。

    <!--验证每个小队每天只能有一条日报 -小队-->
    <select id="selectDayTeamByDateAndOrgCode" parameterType="hashmap" resultType="hashmap">
     <![CDATA[
     select * 
         from dh_rpt_fa_day_team dt where dt.bsflag='0'
     and to_char(dt.report_date,'yyyy-mm-dd') = #{reportDate}
     and dt.org_code = #{orgCode}
    ]]>
    </select>

通过数据库查询数据的条数。

如上左边数据库已经存在了一条2018-02-02日期的数据,当右边添加数据选择这个日期时,文本框提示该日期的日报已经存在,并且不能上报。

 满意请支持一下:

  

yian
原文地址:https://www.cnblogs.com/xiangpeng/p/8471829.html