关于mybatis-plus逻辑删除无效的问题

时间:2021-12-14 03:32:39

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

?
1
2
3
4
5
6
/**
     * 是否删除
     */
    @TableLogic(value = "0", delval = "1")
    @TableField(value = "del_flag")
    private Boolean delFlag;

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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();
    }
 
}

到此这篇关于mybatis-plus逻辑删除无效的文章就介绍到这了,更多相关mybatis-plus逻辑删除内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/hjieone/p/15304837.html