static {
NutConf.DAO_USE_POJO_INTERCEPTOR = false;
}
该特性在哪里配置
static {
NutConf.DAO_USE_POJO_INTERCEPTOR = false;
}
该特性在哪里配置
@wendal 进不去拦截器,代码如下
拦截器
@IocBean(name="archivesPojoInterceptor")
public class ArchivesPojoInterceptor extends DefaultPojoInterceptor {
protected void setupFieldAnnotation(final MappingField mf, final Field field, final Annotation anno) {
super.setupFieldAnnotation(mf,field,anno);
if (anno instanceof DAS_AJJBXX) {
super.list.add(new BasicPojoInterceptor() {
public void onEvent(Object obj, Entity<?> en, String event, Object... args) {
if ("prevUpdate".equals(event)){
// 对obj进行操作
// MappingField有字段信息
// Field的java属性反射对象
}
}
});
}
}
}
实体类
@Table(value="DAS_AJJBXX",interceptor= ArchivesPojoInterceptor.class)
@TableIndexes({@Index(name = "INDEX_DAS_AJJBXX_ajh", fields = {"ajh"},unique=false),
@Index(name = "INDEX_DAS_AJJBXX_lsh", fields = {"lsh"},unique=false),@Index(name = "INDEX_DAS_AJJBXX_mlsx", fields = {"mlsx"},unique=false)
})
public class DAS_AJJBXX extends BaseModel implements Serializable{
private static final long serialVersionUID=1L;
写了另外一种好像不对,拿到的数据是更新前的,能拦截到更新后或者插入后的状态吗
public class ArchivesDaoInterceptor implements DaoInterceptor {
@Override
public void filter(DaoInterceptorChain chain) throws DaoException {
DaoStatement st = chain.getDaoStatement();
if (st instanceof NutPojo) {
if(st.isInsert()||st.isUpdate()){
String untityname=st.getEntity().getTableName();
try {
if ("DAS_AJJBXX".equals(untityname)) {
String ajid = ((DAS_AJJBXX) ((NutPojo) st).params().get(0)).getId();
if (!StringUtils.isEmpty(ajid)) {
SearchServiceImpl s = null;
try {
s = Mvcs.ctx().getDefaultIoc().get(SearchServiceImpl.class);
s.updateIndex(ajid);
} catch (IocException e) {
e.printStackTrace();
}
}
}
写了另外一种好像不对,拿到的数据是更新前的,能拦截到更新后或者插入后的状态吗
public class ArchivesDaoInterceptor implements DaoInterceptor {
@Override
public void filter(DaoInterceptorChain chain) throws DaoException {
DaoStatement st = chain.getDaoStatement();
if (st instanceof NutPojo) {
if(st.isInsert()||st.isUpdate()){
String untityname=st.getEntity().getTableName();
try {
if ("DAS_AJJBXX".equals(untityname)) {
String ajid = ((DAS_AJJBXX) ((NutPojo) st).params().get(0)).getId();
if (!StringUtils.isEmpty(ajid)) {
SearchServiceImpl s = null;
try {
s = Mvcs.ctx().getDefaultIoc().get(SearchServiceImpl.class);
s.updateIndex(ajid);
} catch (IocException e) {
e.printStackTrace();
}
}
}