67,513
社区成员
发帖
与我相关
我的任务
分享
public class MyNameStrategy extends DefaultNamingStrategy{
@Override
public String classToTableName(String className) {
if(className.equals("Comment")) {
className = className+new Date();
}
return super.classToTableName(className);
}
}
DateFormat format = new SimpleDateFormat("yyyyMM");
String currentDate = format.format(new Date());
if("AccessLog".equals(className)){
return "joye_access_" + currentDate;
}
当传过来的参数为AccessLog时,返回表名为joye_access_201404这张表,以后对AccessLog这个类的操作都是基于joye_access_201404这个表(前提是当前是2014年4月),你要想查询前一天的数据,那么你获取到前一天日期就可以了啊!
总之,你return时写上表名前缀,加上动态时间部分,组成一个完整的表中(这里return的表名要在数据库中真实存在的一张表)