1. 首先创建分区数据表(详见:MySQL按日期月份分区实例详解)
2. 创建复合主键的组件类
需要注意@Embeddable用来标示此类是复合主键类,必须要覆盖equals和hashCode两个方法
@Embeddable
public class TestId implements Serializable {
private static final long serialVersionUID = -1875863517212408875L;
private Integer id;
private Date date;
//getter、setter方法省略
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final <span style="font-family:Arial, Helvetica, sans-serif;">TestId </span><span style="font-family:Arial, Helvetica,