1:判断是否为null
if (true == InputChecker.MustCheck(bean.getSearchSeikyuu_s_ymd_from())
|| true == InputChecker.MustCheck(bean.getSearchSeikyuu_s_ymd_to())) {
sb.append(Properties.getMsg("HA.ERROR.001",
new String[] { "請求開始日" }, true));
}
InputChecker.java
public static boolean MustCheck(String str){
if(!StringUtil.isNull(str)){
return false;
}
return true;
}
2:判断是否为日期格式:
//日付形式
boolean bError = false;
// 請求開始日From
if(false == InputChecker.isYMD(bean.getSearchSeikyuu_s_ymd_from(), "yyyy/MM/dd")){
sb.append("請求開始日(FROM)"+Properties.getMsg("HA.ERROR.Ymd",true));
bError=true;
}
public static boolean isYMD(String source, String format) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setLenient(false);
ParsePosition position = new ParsePosition(0);
Date date = sdf.parse(source, position);
if (position.getErrorIndex() != -1) {
// パース失敗
return false;
} else {
// パース成功
if (position.getIndex() != source.length()) {
// 厳密には失敗
return false;
}
}
} catch (Exception e) {
return false;
}
return true;
}
3.比较前后两个日期大小:
if (!bError){
CommonService.compareYmd(bean.getSearchSeikyuu_s_ymd_from(),
bean.getSearchSeikyuu_s_ymd_to(), "請求開始日", sb);
if (StringUtil.isNull(sb.toString())){
// 管理マスタ.請求対象一覧検索最大期間を取得する
int kanri_num = CommonService.getKanriNum(409);
String date_to = bean.getSearchSeikyuu_s_ymd_to();
Date fromDt1 = DateUtil.addMonths(
DateUtil.parseDate(date_to), -kanri_num);
String date_from = DateUtil.formatYMD(fromDt1);
if (!DateUtil.between(bean.getSearchSeikyuu_s_ymd_from(),
date_from, date_to)) {
sb.append(Properties.getMsg("HA.ERROR.131",
new String[] { "請求開始日", kanri_num + "ヶ月" },
true));
}
}
public static void compareYmd(String from,String to,String name,StringBuffer sb) throws Exception{
if(!StringUtil.isNull(from)&&!StringUtil.isNull(to)){
if(from.compareTo(to)>0){
sb.append(Properties.getMsg("HA.ERROR.012",new String[] {name+"(開始日)", name+"(終了日)"},true));
}
}
}