欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis-Plus中通用枚舉的實(shí)現(xiàn)

 更新時(shí)間:2024年05月07日 10:35:59   作者:老貓喜歡今日爬山  
表中的有些字段值是固定的此時(shí)我們可以使用MyBatis-Plus的通用枚舉來(lái)實(shí)現(xiàn),本文主要介紹了MyBatis-Plus中通用枚舉的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下

表中的有些字段值是固定的,例如性別(男或女),此時(shí)我們可以使用MyBatis-Plus的通用枚舉來(lái)實(shí)現(xiàn)

1.數(shù)據(jù)庫(kù)表添加字段sex

2.創(chuàng)建通用枚舉類(lèi)型

package com.atguigu.mp.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
@Getter
public enum SexEnum {
    MALE(1, "男"),
    FEMALE(2, "女");
    @EnumValue
    private Integer sex;
    private String sexName;

    SexEnum(Integer sex, String sexName) {
        this.sex = sex;
        this.sexName = sexName;
    }
}

3.配置掃描通用枚舉

mybatis-plus:
    configuration:
        # 配置MyBatis日志
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    global-config:
        db-config:
        # 配置MyBatis-Plus操作表的默認(rèn)前綴
        table-prefix: t_
        # 配置MyBatis-Plus的主鍵策略
        id-type: auto
    # 配置掃描通用枚舉
    type-enums-package: com.atguigu.mybatisplus.enums

4.測(cè)試

@Test
public void testSexEnum(){
    User user = new User();
    user.setName("Enum");
    user.setAge(20);
    //設(shè)置性別信息為枚舉項(xiàng),會(huì)將@EnumValue注解所標(biāo)識(shí)的屬性值存儲(chǔ)到數(shù)據(jù)庫(kù)
    user.setSex(SexEnum.MALE);
    //INSERT INTO t_user ( username, age, sex ) VALUES ( ?, ?, ? )
    //Parameters: Enum(String), 20(Integer), 1(Integer)
    userMapper.insert(user);
}

到此這篇關(guān)于MyBatis-Plus中通用枚舉的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)MyBatis-Plus 通用枚舉內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論