zoukankan      html  css  js  c++  java
  • mybatis-plus逻辑删除无效

    添加如下注解value代表默认值delval代表删除时的值

        /**
         * 是否删除
         */
        @TableLogic(value = "0", delval = "1")
        @TableField(value = "del_flag")
        private Boolean delFlag;
    MybatisPlusConfig添加如下bean,不出意外这里只针对mybatis-plus 3.1.1之上版本的这里是最关键的
        @Bean
        public ISqlInjector sqlInjector(){
            return new DefaultSqlInjector();
        }

    下图是配置全部代码(如您知道上一步配置该添加到哪里,那就请忽略下面的代码配置)

    import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
    import com.baomidou.mybatisplus.core.injector.ISqlInjector;
    import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.databind.module.SimpleModule;
    import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
    
    /**
     * mybatis-plus配置
     **/
    @Configuration
    @MapperScan({"com.sjyf.gym.mapper.**", "com.sjyf.gym.mapper"})
    public class MybatisPlusConfig {
    
        /**
         * 分页插件
         */
        @Bean
        public PaginationInterceptor paginationInterceptor() {
            return new PaginationInterceptor();
        }
    
        /**
         * 分页
         * @param builder
         * @return
         */
        @Bean
        public ObjectMapper objectMapper (Jackson2ObjectMapperBuilder builder) {
            ObjectMapper objectMapper = builder.createXmlMapper(false).build();
            SimpleModule simpleModule = new SimpleModule();
            // 直接将所有的Long类型转换为String
            simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
            simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
            objectMapper.registerModule(simpleModule);
            return objectMapper;
        }
    
        /**
         * 逻辑删除
         * @return
         */
        @Bean
        public ISqlInjector sqlInjector(){
            return new DefaultSqlInjector();
        }
    
    }
  • 相关阅读:
    Insertion Sort List
    Max Points on a Line
    Evaluate Reverse Polish Notation
    vue路由传参的三种基本方式
    如何搭建一个vue项目
    vue路由跳转时更改页面title
    CSS清除浮动大全共8种方法
    border:none 与border:0的区别
    for..in和for..of的功能
    IE浏览器兼容问题-----html和css的兼容写法
  • 原文地址:https://www.cnblogs.com/hjieone/p/15304837.html
Copyright © 2011-2022 走看看