Python 官方文档:入门教程 => 点击学习
目录新增获取自增列id1、实体类定义2、解决办法 3、调用方法获取id说明解决id自增方法新增获取自增列id 1、实体类定义 注意:@TableId(value = &ld
注意:@TableId(value = “id”, type = IdType.AUTO)注解中的 type = IdType.AUTO 属性标注主键为自增策略。
import lombok.Data;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
@Data
@TableName("users")
public class User {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("`name`")
private String name;
}
方法一:
使用框架自带的insert方法。
int insert(T entity);
方法二:
@Insert("insert into users(`name`) values(#{user.name})")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
Integer add(@Param("user") User user);
方法三:
@InsertProvider(type = UserMapperProvider.class, method = "add")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
Integer add(@Param("user") User user);
UserMapperProvider类
public class UserMapperProvider {
public String add(User user) {
return "insert into users(id, `name`) values(#{user.id},#{user.name})";
}
}
方法调用前:
方法调用后:
在pojo文件中id加入
@TableId(value = “id”,type = IdType.AUTO)
application.yml中加入:
global-config:
db-config:
id-type: auto
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: Mybatis-Plus 新增获取自增列id方式
本文链接: https://www.lsjlt.com/news/162569.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0