mybatisplus IdType.NONE
时间: 2023-09-22 13:11:41 浏览: 64
Mybatis-Plus is a popular library in the Java ecosystem that enhances the functionality of MyBatis, a lightweight persistence framework. When defining entity classes in Mybatis-Plus, you can specify the ID type using the `@TableId` annotation.
The `IdType` enum in Mybatis-Plus provides different options for ID generation strategies. The `NONE` value of `IdType` indicates that the ID column will not be auto-generated or assigned by any strategy. It means that you need to manually set the ID value when inserting a new record into the database.
Here's an example of how you can use `IdType.NONE` with MyBatis-Plus:
```java
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@TableName("my_table")
public class MyEntity {
@TableId(type = IdType.NONE)
private Long id;
// Other class members and methods
}
```
In this example, the `id` field of the `MyEntity` class is annotated with `@TableId(type = IdType.NONE)`, indicating that the ID will not be generated automatically.