| |
| |
| |
| @TableName("t_user") |
| |
| |
| |
| |
| mybatis-plus: |
| |
| global-config: |
| db-config: |
| |
| table-prefix: t_ |
| # 在主键id上添加如下注解,表明该属性对应表中的主键 |
| @TableId |
| private Long id; |
| |
| # 当实体类中的主键字段与数据库表中的主键id名称不一致时,可以指定value属性 |
| @TableId("uid") |
| private Long id; |
| |
| # 查看该注解的type属性,默认为none |
| # 不指定时为none,mybatis plus使用雪花算法 |
| @Documented |
| @Retention(RetentionPolicy.RUNTIME) |
| @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) |
| public @interface TableId { |
| String value() default ""; |
| |
| IdType type() default IdType.NONE; |
| } |
| |
| # 其他值如下 |
| public enum IdType { |
| AUTO(0), |
| NONE(1), |
| INPUT(2), |
| ASSIGN_ID(3), |
| ASSIGN_UUID(4); |
| |
| private final int key; |
| |
| private IdType(int key) { |
| this.key = key; |
| } |
| |
| public int getKey() { |
| return this.key; |
| } |
| } |
| |
| # 方式1 |
| # 如果想设置为主键自增,需设置为如下,同时数据库表的主键也设置为自增 |
| @TableId(value = "uid", type = IdType.AUTO) |

| |
| |
| |
| @TableId("uid") |
| private Long id; |
| |
| mybatis-plus: |
| |
| global-config: |
| db-config: |
| |
| id-type: auto |
| |
| |
| @TableId("uid") |
| private Long id; |
| |
| |
| @TableField(value = "xxx",fill = FieldFill.UPDATE) |
| # 数据库中新增1个字段deleted,设置默认值为0 |
| # 实体类中添加属性如下 |
| @TableLogic |
| private Integer deleted; |
| # 测试删除功能,真正执行的是修改 |
| UPDATE t_user SET is_deleted=1 WHERE id=? AND is_deleted=0 |
| # 测试查询功能,被逻辑删除的数据默认不会被查询 |
| SELECT id,username AS name,age,email,is_deleted FROM t_user WHERE is_deleted=0 |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术