EasyUI驗證擴充,easyui驗證

來源:互聯網
上載者:User

EasyUI驗證擴充,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})@ResponseBodypublic 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日期的資料,當右邊添加資料選擇這個日期時,文字框提示該日期的日報已經存在,並且不能上報。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.