String date1=vatfpkplAlertTjnsr.getSssqq(); //输入的日期,另外data1也可以直接通过c.setTime(new Date());获取当前日期
// 新建一个日历对象。注意:类Calendar是抽象的要使用getInstance()实例化,或者实例化其子类
Calendar c=Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
if("0".equals(vatfpkplAlertTjnsr.getDbfs())){
c.setTime(sdf.parse(date1));
c.add(Calendar.MONTH, -1);//上个月
}else if("1".equals(vatfpkplAlertTjnsr.getDbfs())){
c.setTime(sdf.parse(date1));
c.add(Calendar.YEAR, -1);//上一年
}
String date2=sdf.format( c.getTime());
vatfpkplAlertTjnsr.setLastMonth_Year(date2);
page.getParams().put("LastMonth_Year", date2);
之后再xml文件中调用LastMonth_Year
xml文件 : where date_format(re.SSSQ,'%Y-%m')=#{params.LastMonth_Year}
注释:getInstance是一个函数。在java中,可以使用这种方式使用单例模式创建类的实例,所谓单例模式就是一个类有且只有一个实例,不像object ob=new object();的这种方式去实例化后去使用。