We know that in the last beta version of easydbo, annotations are added to configure object and relational table ing. Some time ago, I saw how to configure the primary key attribute and primary key generator in the annotation. Because the default configuration is used in the development documentation, the following example is used in this document:
ImportJava. Io. serializable;
ImportJava. util. date;
ImportCom. easyjf. DBO. annotation .*;
@ Table (tablename = "message ")
Public ClassMessage
ImplementsSerializable {
@ Tablefield (name = "CID ")
Private StringCID;
@ Tablefield (name = "title ")
PrivateString title1;
@ Tablefield (name = "content ")
PrivateString content1;
@ Tablefield (name = "inputuser ")
PrivateString inputuser;
@ Tablefield (name = "inputtime ")
PrivateDate inputtime;
@ Tablefield (name = "publish ")
PrivateBoolean publish1;
@ Tablefield (name = "status ")
PrivateInteger status1;
PublicString getcid (){
ReturnCID;
}
Public VoidSetcid (string CID ){
This. Cid = CID;
}
//...
// Other getter and setter Methods
} This section does not demonstrate how to configure the primary key attribute and generator. Let's take a look at the source code of the two tags @ table and @ tabelfield: Package COM. easyjf. DBO. annotation; import Java. lang. annotation. retention;
Import java. Lang. annotation. retentionpolicy;
/**
* Labels used to define the table structure
* @ Author Daxia
*
*/
@ Retention (retentionpolicy. runtime)
Public @ interface table {
/**
* Table Name
* @ Return
*/
String tablename ();
/**
* Table Primary Key
* @ Return
*/
String keyfield () Default "CID ";
/**
* Primary key value Generator
* @ Return
*/
String keygenerator () Default "com. easyjf. DBO. randomidgenerator ";
} As can be seen from the source code, @ table has three attributes, tablename is used to define the table name, keyfield is used to define the primary key attribute, and keygenerator is used to define the primary key generator. Keyfield and keygenerator have a default value. Because the default value is used in the previous message class definition, keyfield and keygenerator are not used. To customize your default value, you can write it as follows: @ table (tablename = "message", keyfield = "ID", keygenerator = "com. easyjf. DBO. nul1_generator ")
Public ClassMessage
ImplementsSerializable {...} Let's take a look at the source file @ tablefield: Package com. easyjf. DBO. annotation; import java. Lang. annotation. retention;
Import java. Lang. annotation. retentionpolicy;
/**
* Tags used to define table fields
* @ Author Daxia
*
*/
@ Retention (retentionpolicy. runtime)
Public @ interface tablefield
{
Public string name ();
Boolean lazy () default false;
Boolean unique () default false;
} Because lazy and unique have been given the default values, we can see that only the examples corresponding to the attributes are defined in the example. @ Tablefield only defines common attributes, and also has attributes such as onetoone, manytoone, and manytoquota. For details, see easydbo development documentation. Http://www.easyjf.com/easydbo/devguide.htm In addition, the annotation configuration should also be added to some of the more suitable content in the official version, easydbo will also make some adjustments, please pay attention!