Search in sources :

Example 1 with MetaObjectHandler

use of com.baomidou.mybatisplus.core.handlers.MetaObjectHandler in project muses by acgist.

the class MyBatisAutoConfiguration method metaObjectHandler.

@Bean
@ConditionalOnMissingBean
public MetaObjectHandler metaObjectHandler(@Autowired IdService idService) {
    return new MetaObjectHandler() {

        @Override
        public void insertFill(MetaObject metaObject) {
            final Date date = new Date();
            this.setFieldValByName(BootEntity.PROPERTY_CREATE_DATE, date, metaObject);
            this.setFieldValByName(BootEntity.PROPERTY_MODIFY_DATE, date, metaObject);
        }

        @Override
        public void updateFill(MetaObject metaObject) {
            this.setFieldValByName(BootEntity.PROPERTY_MODIFY_DATE, new Date(), metaObject);
        }
    };
}
Also used : MetaObject(org.apache.ibatis.reflection.MetaObject) Date(java.util.Date) MetaObjectHandler(com.baomidou.mybatisplus.core.handlers.MetaObjectHandler) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MetaObjectHandler

use of com.baomidou.mybatisplus.core.handlers.MetaObjectHandler in project muses by acgist.

the class MyBatisAutoConfiguration method metaObjectHandler.

@Bean
@ConditionalOnMissingBean
public MetaObjectHandler metaObjectHandler(@Autowired IdService idService) {
    return new MetaObjectHandler() {

        @Override
        public void insertFill(MetaObject metaObject) {
            final LocalDateTime now = LocalDateTime.now();
            this.setFieldValByName(BootEntity.PROPERTY_CREATE_DATE, now, metaObject);
            this.setFieldValByName(BootEntity.PROPERTY_MODIFY_DATE, now, metaObject);
        }

        @Override
        public void updateFill(MetaObject metaObject) {
            final LocalDateTime now = LocalDateTime.now();
            this.setFieldValByName(BootEntity.PROPERTY_MODIFY_DATE, now, metaObject);
        }
    };
}
Also used : LocalDateTime(java.time.LocalDateTime) MetaObject(org.apache.ibatis.reflection.MetaObject) MetaObjectHandler(com.baomidou.mybatisplus.core.handlers.MetaObjectHandler) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MetaObjectHandler (com.baomidou.mybatisplus.core.handlers.MetaObjectHandler)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 LocalDateTime (java.time.LocalDateTime)1 Date (java.util.Date)1