有几个表的某个字段必须唯一,可不可以在POJO中用注解设置?
6 回复
@wendal 不知道怎么用呀,API里面就写了个
org.nutz.dao.entity.annotation
注释类型 TableIndexes
@Retention(value=RUNTIME)
@Target(value=TYPE)
@Documented
public @interface TableIndexes
声明一组数据表的索引
作者:
zozoh(zozohtnt@gmail.com)
另请参阅:
Index
必需元素概要
所需元素
限定符和类型 必需的元素和说明
Index[] value
元素详细资料
value
public abstract Index[] value
package cn.wizzer.modules.lock.entities;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.Index;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.entity.annotation.TableIndexes;
import cn.wizzer.modules.lock.model.AreaInfoModel;
/**
*
* 锁
*
*/
@Table("lock_info")
@TableIndexes({@Index(name="lock_num_index",fields={"lockNum"},unique=true)})
public class LockInfo extends BaseBean {
@Comment("锁号:(3位字母+7位数字,如HLL0000001)")
@Column("lock_num")
private String lockNum;
@Comment("锁结构(三种:全开、半开、闭合)")
@Column("lock_stc")
private Long lockStc;
@Comment("锁版本(第几代,可能会有版本编号)")
@Column("lock_model")
private String lockModel;
@Comment("备注信息")
@Column("lock_remark")
private String lockRemark;
@Comment("锁状态(激活:1,废弃:2,剪断:3)")
@Column("lock_status")
private Long lockStatus;
@Comment("所属片区(关联片区表)")
@Column("lock_area_id")
private String lockAreaId;
public void setLockNum(String lockNum){
this.lockNum = lockNum;
}
public String getLockNum(){
return this.lockNum;
}
public void setLockStc(Long lockStc){
this.lockStc = lockStc;
}
public Long getLockStc(){
return this.lockStc;
}
public void setLockModel(String lockModel){
this.lockModel = lockModel;
}
public String getLockModel(){
return this.lockModel;
}
public void setLockRemark(String lockRemark){
this.lockRemark = lockRemark;
}
public String getLockRemark(){
return this.lockRemark;
}
public void setLockStatus(Long lockStatus){
this.lockStatus = lockStatus;
}
public Long getLockStatus(){
return this.lockStatus;
}
public void setLockAreaId(String lockAreaId){
this.lockAreaId = lockAreaId;
}
public String getLockAreaId(){
return this.lockAreaId;
}
}
我加了,还是能插入重复的呢?
@wendal 那现在表已经用了很久了,是要手动修改么?
添加回复
请先登陆