Learn extjs5 with me (29 -- add module and menu Definition [2 create java bean])

Source: Internet
Author: User

Learn extjs5 with me (29 -- add module and menu Definition [2 create java bean])
Learn extjs5 with me (29 -- add module and menu Definition [2 create java bean])

Create bean files in java for the four modules added in the previous section. After the preceding table is created, you need to create a java bean file. You need to add several support classes before creating them. Create the annotation package in com. jfok. server. common, and then add two class libraries below. These two are custom annotation classes. It is used to annotate the information of each module and the information of each field in the module.

Package com. jfok. server. common. annotation; import java. lang. annotation. retention; import java. lang. annotation. retentionPolicy;/*** used to comment out the module ** @ author jiangfeng */@ Retention (RetentionPolicy. RUNTIME) public @ interface TableDefine {// id of this table, which is a four-digit int id (); // Module name String title (); // module abbreviation String shortname () default ""; // module group name String group (); // whether the primary key of the module can be classified. If yes, it can be defined as "2, 2", indicating that there are three levels, each level of code is 2 bits, // For example, the accounting subject can be defined as // 10 // 1001 // 100101 // 100102 // 100102 // 1002 //...... string codeLevel () default ""; // whether the module has an attachment boolean attachment () default false ;}

Package com. jfok. server. common. annotation; import java. lang. annotation. retention; import java. lang. annotation. retentionPolicy;/*** used to comment out each field in the module ** @ author jiangfeng **/@ Retention (RetentionPolicy. RUNTIME) public @ interface FieldDefine {String title (); int number () default 0; String remark () default ""; boolean nameField () default false; boolean hidden () default false; String fieldGroup () default "default group ";}

Create the package system in com. jfok. server. hibernate and put all the bean files used by the system in this directory. Create an interface file first:
Package com. jfok. server. hibernate. system;/*** classes with this interface are all control classes of the system module ** @ author jfok **/public interface _ IModuleControlInterface {}

Create _ ModuleGroup. java
Package com. jfok. server. hibernate. system; import java. io. serializable; import javax. persistence. column; import javax. persistence. entity; import javax. persistence. id; import com. jfok. server. common. annotation. fieldDefine; import com. jfok. server. common. annotation. tableDefine;/*** module grouping class, each module has a major grouping ** @ author jfok 2012.11.7 */@ SuppressWarnings ("serial") @ Entity@org.hibernate.annotations.Entity (dynamicUpdate = true) @ TableDefine (group = "system module", id = 9901, title = "module group") public class _ ModuleGroup implements _ IModuleControlInterface, serializable {public static final String TITLE = "tf_title"; @ Id @ FieldDefine (title = "module Group No.", number = 10) @ Column (nullable = false, length = 10) private String tf_moduleGroupId; @ FieldDefine (title = "module group name", nameField = true, number = 20) @ Column (nullable = false, length = 50) private String tf_title; @ FieldDefine (title = "Description", number = 30) private String tf_description; @ FieldDefine (title = "icon address", number = 40) private String tf_iconURL; @ FieldDefine (title = "Remarks", number = 50) private String tf_remark; public _ ModuleGroup () {}// setter and getter}
In the above class, the User-Defined annotation class is used for annotation. One is the Annotation on the class name, and the other is the Annotation on each field. The function of these two types of annotations is that when a module is added in the future, the information of these annotations will be automatically added to the table of the saved module and module fields.

Add _ Module. java
Package com. jfok. server. hibernate. system; import java. io. serializable; import javax. persistence. cascadeType; import javax. persistence. column; import javax. persistence. entity; import javax. persistence. fetchType; import javax. persistence. id; import javax. persistence. joinColumn; import javax. persistence. manyToOne; import org. codehaus. jackson. map. annotate. jsonSerialize; import com. jfok. server. common. annotation. F IeldDefine; import com. jfok. server. common. annotation. tableDefine;/*** the meaning of each module in the system ** @ author jfok 2012.11.7 **/@ JsonSerialize (include = JsonSerialize. permission Sion. NON_EMPTY) @ SuppressWarnings ("serial") @ Entity@org.hibernate.annotations.Entity (dynamicUpdate = true) @ TableDefine (group = "system module", id = 9902, title = "system module ") public class _ Module implements _ IModuleControlInterface, Serializable {public static Final String MODULEID = "tf_moduleId"; public static final String MODULENAME = "tf_moduleName"; @ Id @ FieldDefine (title = "module Id", number = 10) @ Column (nullable = false, length = 10) private String tf_moduleId; // module ID, module serial number @ ManyToOne (cascade = CascadeType. REFRESH, fetch = FetchType. EAGER) @ JoinColumn (name = "tf_moduleGroupId") @ FieldDefine (title = "module group", number = 20) private _ ModuleGroup tf_ModuleGroup ;@ FieldDefine (title = "module ID", number = 30) @ Column (nullable = false, length = 50, updatable = false) private String tf_moduleName; // Module name @ FieldDefine (title = "module name", nameField = true, number = 40) @ Column (nullable = false, length = 50) private String tf_title; // Chinese module name @ FieldDefine (title = "module abbreviation", number = 50) @ Column (length = 20) private String tf_shortname; // @ FieldDefine (title = "", number = 60) @ Column (length = 20) private String tf_englishname; // abbreviation. When adding a sequence number, you can add this letter to @ FieldDefine (title = "table name ", number = 70) @ Column (length = 50) private String tf_tableName; @ FieldDefine (title = "primary key", number = 80) @ Column (nullable = false, length = 50) private String tf_primaryKey; // module primary key @ FieldDefine (title = "display flag field", number = 81) @ Column (nullable = false, length = 50) private String tf_nameFields; // key modules For example, the contract name and department name @ FieldDefine (title = "record title tpl", number = 82, remark = "if the display flag field cannot describe the record, you need to set this content") @ Column (length = 200) private String tf_titleTpl; // key fields of the module, if the contract is the contract name, the Department name is @ FieldDefine (title = "encoding field", number = 91) @ Column (length = 50) private String tf_codeField; // module encoding field, if any, @ FieldDefine (title = "sequence number field", number = 97) @ Column (length = 50) private String tf_orderField; // module encoding field, if yes, @ FieldD Efine (title = "Date Field", number = 92) @ Column (length = 50) private String tf_dateField; @ FieldDefine (title = "year field", number = 93) @ Column (length = 50) private String tf_yearfield; @ FieldDefine (title = "monthly field", number = 94) @ Column (length = 50) private String tf_monthField; @ FieldDefine (title = "quarterly field", number = 95) @ Column (length = 50) private String tf_seasonField; @ FieldDefine (title = "file field", number = 96) @ Column (Length = 50) private String tf_fileField; @ FieldDefine (title = "homepage order", number = 99) @ Column (length = 50) private String tf_homePageTag; @ FieldDefine (title = "module description", number = 100) @ Column (length = 50) private String tf_description; @ FieldDefine (title = "request address", number = 110) @ Column (nullable = false, length = 50) private String tf_requestMapping; // the user that calls the backend service in the system. do, employee. do, etc. @ FieldDefine (title = "icon Address ", number = 120) @ Column (length = 50) private String tf_iconURL; @ FieldDefine (title =" Default sorting field ", number = 130) private String tf_defaultOrderField; @ FieldDefine (title = "row operation", remark = "add and modify operations can be completed within", number = 140) @ Column (nullable = false) private Boolean tf_isInlineOper; // if the department code is, 2 @ FieldDefine (title = "encoding level", remark = "If encoding level is set, the length of the primary key must be in this level, and the parent code must exist ", number = 150) @ Column (length = 50) Str Ing tf_codeLevel; @ FieldDefine (title = "linkage module", remark = "after adding, deleting, and modifying data in this module, all opened linkage modules must refresh the data. ", Number = 155) @ Column (length = 200) private String tf_modules module; @ FieldDefine (title =" available ", number = 160) @ Column (nullable = false) private Boolean tf_isEnable = false; @ FieldDefine (title = "browsed", number = 170) @ Column (nullable = false) private Boolean tf_hasBrowse = false; @ FieldDefine (title = "can be added", number = 180) @ Column (nullable = false) private Boolean tf_hasInsert = false; @ FieldDefine (title = "modifiable ", number = 190) @ Column (nullable = false) private Boolean tf_hasEdit = false; @ FieldDefine (title = "deleteable", number = 200) @ Column (nullable = false) private Boolean tf_hasDelete = false; @ FieldDefine (title = "executable", number = 210) @ Column (nullable = false) private Boolean tf_hasExec = false; @ FieldDefine (title = "auditable", number = 220) @ Column (nullable = false) private Boolean tf_hasAuditing = false; @ FieldDefine (title = "auditable ", number = 230) @ Column (nullable = false) private Boolean tf_hasApprove = false; @ FieldDefine (title = "payable", number = 240) @ Column (nullable = false) private Boolean tf_hasPayment = false; @ FieldDefine (title = "with attachment", number = 250) @ Column (nullable = false) private Boolean tf_hasAddition = false; // whether the attachment @ FieldDefine is required (title = "permission setting", remark = "you can set permissions for this module and select to browse and operate", number = 260) @ Column (nullable = false) private Boolean tf_canLimit = false; // whether this module can set permissions @ FieldDefine (title = "Excel import ", remark = "Can I import new records through Excel", number = 270) @ Column (nullable = false) private Boolean tf_allowInsertExcel = false; @ FieldDefine (title = "Excel modify ", remark = "whether Excel files can be exported can be modified before importing", number = 280) @ Column (nullable = false) private Boolean tf_allowEditExcel = false; @ FieldDefine (title = "", number = 290) @ Column (nullable = false) private Boolean tf_hasChart = false; @ FieldDefine (title = "system module ", number = 300, remark = "if it is a system module and you do not have permission to browse, the module definition will not be sent to the front-end") @ Column (nullable = false) private Boolean tf_isSystem = false; @ FieldDefine (title = "query condition sequence number", number = 310, remark = "order of this module in the Condition Selection column of the comprehensive query") private Integer tf_searchCondOrder; @ FieldDefine (title = "Remarks", number = 800) private String tf_remark; public _ Module () {}// setter and getter}

_ MenuGroup. java
Package com. jfok. server. hibernate. system; import java. io. serializable; import java. util. list; import javax. persistence. column; import javax. persistence. entity; import javax. persistence. id; import javax. persistence. transient; import com. jfok. server. common. annotation. fieldDefine; import com. jfok. server. common. annotation. tableDefine;/*** menu group ** @ author jfok **/@ SuppressWarnings ("serial") @ Entity@org.hibernate.annotations.Entity (dynamicUpdate = true) @ TableDefine (group = "system module ", id = 9920, title = "menu group") public class _ MenuGroup implements _ IModuleControlInterface, Serializable {@ Id @ FieldDefine (title = "Sn ", remark = "the menu group is displayed on the menu bar by sequence number", number = 10) @ Column (length = 10, nullable = false) private String tf_menuGroupId; @ FieldDefine (title = "group name", nameField = true, number = 20) @ Column (length = 50, nullable = false) private String tf_title; @ FieldDefine (title = "Expand", remark = "expand in tree menu", number = 30) private Boolean tf_expand; @ FieldDefine (title = "icon glyph ", number = 40) private Boolean tf_glyph; @ FieldDefine (title = "icon file name", remark = "icon placed in/images/module/directory", number = 50) @ Column (length = 50) private String tf_iconURL; @ FieldDefine (title = "group description", number = 60) @ Column (length = 50) private String tf_description; @ FieldDefine (title = "Remarks", number = 70) private String tf_remark; @ Transientprivate List <_ MenuModule> tf_menuModules; public _ MenuGroup () {}// setter and getter}

_ MenuModule. java
Package com. jfok. server. hibernate. system; import java. io. serializable; import javax. persistence. cascadeType; import javax. persistence. column; import javax. persistence. entity; import javax. persistence. fetchType; import javax. persistence. generatedValue; import javax. persistence. id; import javax. persistence. joinColumn; import javax. persistence. manyToOne; import org. codehaus. jackson. annotate. jsonIgnore; import org. hibernate. annotations. genericGenerator; import com. jfok. server. common. annotation. fieldDefine; import com. jfok. server. common. annotation. tableDefine;/*** menu items available to the system ** @ author jfok **/@ SuppressWarnings ("serial") @ Entity@org.hibernate.annotations.Entity (dynamicUpdate = true) @ TableDefine (group = "system module", id = 9921, title = "System Menu") public class _ MenuModule implements _ IModuleControlInterface, serializable {@ Id @ FieldDefine (title = "Id", hidden = true, number = 10) @ GeneratedValue (generator = "increment") @ GenericGenerator (name = "increment ", strategy = "increment") private Integer tf_menuModuleId; @ FieldDefine (title = "sequence number", remark = "display by sequence number in the menu", number = 20) @ Column (nullable = false) private Integer tf_orderId; @ JsonIgnore @ ManyToOne (cascade = CascadeType. REFRESH, fetch = FetchType. EAGER) @ JoinColumn (name = "tf_menuGroupId", nullable = false) @ FieldDefine (title = "menu group", nameField = true, number = 30) private _ MenuGroup tf_MenuGroup; @ JsonIgnore @ ManyToOne (cascade = CascadeType. REFRESH, fetch = FetchType. EAGER) @ JoinColumn (name = "tf_moduleId", nullable = false) @ FieldDefine (title = "system Module", number = 40) private _ Module tf_Module; @ FieldDefine (title = "parent menu title", number = 50) @ Column (length = 20) private String tf_parentMenu; @ FieldDefine (title = "separate the next line", number = 60) private Boolean tf_addSeparator; @ FieldDefine (title = "menu title", number = 70) @ Column (length = 50) private String tf_title; @ FieldDefine (title = "parent module constraint Settings", number = 80) private String tf_parentFilter; // This field is used to transmit json to the foreground and put it in json @ Column (insertable = false, updatable = false) private String tf_ModuleId; public _ MenuModule () {}// setter and getter}

Modify hibernate. cfg. xml and add the above four classes to the configuration file.
 
 
  
   
    
Com. microsoft. sqlserver. jdbc. SQLServerDriver
   
   
    
Jdbc: SQL SERVER: // 10.211.55.5: 1433; databaseName = extjs5
   
   
    
Org. hibernate. dialect. SQLServerDialect
   
   
    
Sa
   
   
   
    
False
   
   
    
True
   
   
    
True
   
   
   
   
   
   
  
 


So far, we have created a data table and a java bean file. Now we can develop the content for collaboration in the front and back ends. Directory structure of each file:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.