-
Notifications
You must be signed in to change notification settings - Fork 4
Define
WangTingZheng edited this page Jul 10, 2020
·
2 revisions
In this page, you will learn how to define database and table use Class.
- Create a class, the name of this class will be this table's name.
- Add annotation
OrmTable
to this class. - New a field, the name of field will be the name of a item of this table.
- Add annotation
OrmItem
to this field, this annotation has 3 parameters- type: the type of this item
-
Type: ItemTypeEnum
- TINYINT,SMALLINT,INTEGER,BIGINT,FLOAT,DOUBLE,DECIMAL
- DATE,TIME,YEAR,DATETIME,TIMESTAMP
- CHAR,VARCHAR,TINYBLOB,TINYTEXT,BLOB,TEXT,MEDIUMBLOB,MEDIUMTEXT,LONGBLOB,LONGTEXT;
- length: the length of this item
- Type: long
- isPrimaryKey: is primary key or not
- Type: boolean
- Default: false
- You'd better create set method or initialize table field in construction method
@OrmTable
public class User {
@OrmItem(type = ItemTypeEnum.VARCHAR,length = 1000,isPrimaryKey = true)
private String username;
@OrmItem(type = ItemTypeEnum.VARCHAR,length = 1000)
private String password;
public User() {
}
public User(String username) {
this.username = username;
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
- Create a class, the name of this class will be this database's name.
- Add annotation
OrmDatabase
to this class, this annotation has 7 parameters- type: define this database's type ( database software )
-
Type: DatabaseTypeEnum
- MYSQL: use MySQL as Database
- SQLITE: use SQLITE as Database
- EXTEND: use EXTEND as Database, must define in next parameter
- Default: DatabaseTypeEnum.MYSQL
-
Type: DatabaseTypeEnum
- extendType: define the extend database class, valid when type equals
DatabaseTypeEnum.EXTEND
- Type: Class
- Default: ExtendSample.class. This is a sample, will be ignored when load it.
- host: the host(location) of database
- Type: String
- Default: "localhost:3306"
- username: the username of you database valid account
- Type: String
- Default: "root"
- password: the password of you database valid account
- Type: String
- Default: "root"
- openDatabase: the default database, will use when connect to database software.
- Type: String
- Default: "sys"
- serverTimezone: the time zone of server
- Type: String
- Default: "UTC"
- type: define this database's type ( database software )
- Add table field which you want to add to this database with table class and add
OrmTable
annotation to it.
@OrmDatabase
public class Home {
@OrmTable
public User user;
}