xjs1919 / autodate

mybatis插件,可以给insert和update语句自动添加上create_date和update_date
15 stars 18 forks source link

springboot #2

Open ywcxx1994 opened 5 years ago

ywcxx1994 commented 5 years ago

请问,springboot中,怎么添加两个createDateColumn,updateDateColumn属性

xjs1919 commented 5 years ago

@Configuration public class MybatisConfig { @Bean public Interceptor getInterceptor(){ AutoDateInterceptor interceptor = new AutoDateInterceptor(); Properties properties = new Properties(); properties.put("createDateColumn", "create_date"); properties.put("updateDateColumn", "update_date"); interceptor.setProperties(properties); return interceptor; } }

ywcxx1994 commented 5 years ago

我昨天自己测试,使用这种方式拦截器中的properties会 NPE ,然后我把properties对象当方法参数传进来,不自己new,结果也NPE,我怀疑每次请求拦截器都是不同的对象,因为容器默认的bean是单例嘛,然后我把拦截器中的properties声明为static类型,结果好了。作者能回答一下为什么NPE么?

xjs1919 notifications@github.com 于2019年4月24日周三 上午8:29写道:

@Configuration public class MybatisConfig { @Bean public Interceptor getInterceptor(){ AutoDateInterceptor interceptor = new AutoDateInterceptor(); Properties properties = new Properties(); properties.put("createDateColumn", "create_date"); properties.put("updateDateColumn", "update_date"); interceptor.setProperties(properties); return interceptor; } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xjs1919/autodate/issues/2#issuecomment-486022240, or mute the thread https://github.com/notifications/unsubscribe-auth/AES7KVQFUCCIKGN2BN5LDBLPR6SW3ANCNFSM4HHV5LZA .

xjs1919 commented 5 years ago

不清楚,自己debug下吧