通过扩展mysqldialect来创建一个类,如下所示
public class MySqlDialectExtended extends MySQLDialect {public MySqlDialectExtended() { super(); registerFunction("date_add_interval", new SQLFunctionTemplate(Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)")); registerFunction("date_sub_interval", new SQLFunctionTemplate(Hibernate.DATE, "DATE_SUB(?1, INTERVAL ?2 ?3)")); registerFunction("weekofyear", new StandardSQLFunction("weekofyear", Hibernate.INTEGER)); registerFunction("group_concat", new StandardSQLFunction("group_concat", Hibernate.STRING));}
}
并在查询中像这样使用它
new Query(" >= date_sub_interval(CURRENT_DATE(),1, DAY)");
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)