Learn Extjs5 with me. (35--design of individual modules [3 automatically generate data based on class annotations])

Source: Internet
Author: User

Learn Extjs5 with me. (35--design of individual modules [3 automatically generate data based on class annotations])
Then add in the Hibernate.cfg.xml:

<mapping class= "Com.jfok.server.hibernate.system._modulefield"/><mapping class= " Com.jfok.server.hibernate.system._modulegridscheme "/><mapping class=" com.jfok.server.hibernate.system._ Modulegridschemegroup "/><mapping class=" Com.jfok.server.hibernate.system._modulegridschemegroupfield "/ ><mapping class= "Com.jfok.server.hibernate.system._moduleformscheme"/><mapping class= " Com.jfok.server.hibernate.system._moduleformschemegroup "/><mapping class=" Com.jfok.server.hibernate.system._moduleformschemegroupfield "/>


At this point the data tables for the 7 modules have been added, and the following is the process of automatically generating data from the above 7 classes based on the label information of the class. In other words, you create a new class, using a custom identity language to label each field, you can write the contents of each field to the database according to the information of the label, and you can generate a default list scheme and a form scheme, under which you can add a grouping, and add the fields below the group.

Before this to join a number of support classes, now the size and complexity of the class has increased somewhat, the blog is now very difficult to write, but also can not without the following, I will definitely put the list of modules and the form of these pre-and post-operation of the basic content of the finished.

Most of the configuration of this system is complete, so the automatic generation of module data is also done according to the foreground call. So let's set up a systemframecontroller to do this first. This class is the control class for spring MVC.

Package Com.jfok.server.controller;import Javax.annotation.resource;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.responsebody;import Com.jfok.server.common.moduleservicefunction;import Com.jfok.server.common.annotation.tabledefine;import com.jfok.server.service.systemframeservice;@ Controller@requestmapping ("/systemframe") public class Systemframecontroller {@Resourceprivate systemframeservice systemframeservice;/** * Add the module definition and the field definition according to the class name, generating the default * * @param modulename * @return */@RequestMapping (value = "/addmodule.do", produces = "application/json;text/plain;charset=utf-8")//@Overridepublic @ResponseBodyString Addmodulewithname (String modulename) {class<?> Moduleclass = Moduleservicefunction.getmodulebeanclass ( ModuleName); if (Moduleclass = = null) return "The class was not found in the specified package:" + modulename + "!"; Tabledefine tabledefine = (tabledefine) moduleclass.getannotation (tabledefiNe.class); if (tabledefine = = null) return "The callout definition for tabledefine is not found in the specified class"; String result = Systemframeservice.addmodulewithname (ModuleName, Moduleclass, tabledefine); if (result = = NULL) {// Generate fields for this module Systemframeservice.refreshmodulefield (string.valueof (Tabledefine.id ()));// Create new list Data Systemframeservice.createnewgridscheme (string.valueof (Tabledefine.id ()), moduleclass);// Create a new form data Systemframeservice.createnewformscheme (string.valueof (Tabledefine.id ()), moduleclass);} return null;}}

That is, when you call/systemframe/addmodule.do?modulename=_modulegroup in the foreground, you can automatically add all the field information in the "module group" to the table, and generate a list schema and a form scheme. Enter: Http://localhost:8888/app/systemframe/addmodule.do?moduleName=_ModuleGroup in the browser, you will complete the above work. Let's look at the data added to the table after the completion. (You now input can not increase, so there are a lot of support class you do not, and so on later download the source code on it)



To be able to add this data to the _modulegroup module definition, you need to modify the class

Package Com.jfok.server.service;import Java.util.arraylist;import Java.util.date;import java.util.HashSet;import Java.util.list;import Javax.annotation.resource;import Javax.servlet.http.httpservletrequest;import Org.springframework.stereotype.service;import Org.springframework.transaction.annotation.propagation;import Org.springframework.transaction.annotation.transactional;import Com.jfok.server.dao.systembasedao;import Com.jfok.server.common.info.applicationinfo;import Com.jfok.server.common.info.serviceinfo;import Com.jfok.server.common.info.systeminfo;import Com.jfok.server.common.info.userinfo;import Com.jfok.server.hibernate.system._menugroup;import Com.jfok.server.hibernate.system._module;import Com.jfok.server.hibernate.system._moduleformscheme;import com.jfok.server.hibernate.system._ Moduleformschemegroup;import Com.jfok.server.hibernate.system._modulegridscheme;import Com.jfok.server.hibernate.system._modulegridschemegroup, @Servicepublic class Applicationservice {@ResourceprIvate Systembasedao systembasedao;private static list<_module> modules = null;//Transaction Comment @suppresswarnings (" Unchecked ") @Transactional (propagation = propagation.required, readOnly = true) public ApplicationInfo Getapplicationinfo (HttpServletRequest request) {applicationinfo result = new ApplicationInfo ();//The above content is temporarily customized, It will later be read from the database and the logon information instead. SystemInfo SystemInfo = new SystemInfo () systeminfo.settf_systemname ("Custom small and Medium management system"); systeminfo.settf_systemversion ("2014.09.28"); Result.setsysteminfo (SystemInfo); UserInfo UserInfo = new UserInfo () USERINFO.SETTF_USERDWMC ("Wuxi Hongyu Electronics Co., Ltd."); Userinfo.settf_userstartdate (new Date ()); Userinfo.settf_username ("admin"); Userinfo.settf_loginname ("admin"); Userinfo.settf_userid (0); userinfo.settf_ DepartmentID ("xx"); Userinfo.settf_departmentname ("Engineering Department"); Result.setuserinfo (UserInfo); ServiceInfo serviceinfo = new ServiceInfo () serviceinfo.settf_servicedepartment ("Hee Wang Company"); serviceinfo.settf_ Servicemen ("Shong"); Serviceinfo.settf_servicetelnumber ("1320528xxxx"); Serviceinfo.settf_serVicefaxnumber ("0510-88888888"); Serviceinfo.settf_serviceqq ("7858xxxx"); Serviceinfo.settf_serviceemail ("[Email  protected] Serviceinfo.settf_servicehomepage ("www.www.net"); Serviceinfo.settf_copyrightinfo ("Hee Wang Company All rights reserved" ); Serviceinfo.settf_copyrightowner ("Hee Wang Software"); Result.setserviceinfo (serviceinfo);//Add all the module definition information in Result.settf_ Modules (New Hashset<_module> ((list<_module>) Systembasedao.findall (_module.class));// Add this to let the menu group below the menu also execute the SQL statement added, otherwise, to return to MVC to join the menu,//will be executed in SQL because the session is closed and error for (_module module:result.getTf_ Modules ()) {Module.getmodulefields (). Size (); for (_modulegridscheme scheme:module.getModuleGridSchemes ()) {for (_ Modulegridschemegroup group:scheme.getModuleGridSchemeGroups ()) {Group.getmodulegridschemegroupfields (). Size ();}} For (_moduleformscheme scheme:module.getModuleFormSchemes ()) {for (_moduleformschemegroup Group: Scheme.getmoduleformschemegroups ()) {Group.getmoduleformschemegroupfields (). Size ();}} Add menu group Result.settf_menugroups (list<_menugroup>) Systembasedao.findall (_menugroup.class)); for (_menugroup mg:result.getTf_MenuGroups ()) {// Added this is to let the menu group below the menu also execute the SQL statement added, otherwise, to return to MVC to join the menu,//will be executed in SQL because the session is closed and error mg.gettf_menumodules (). Size (); Modules = new Arraylist<_module> (Result.gettf_modules ()); return result;} Gets the module definition according to the module name number public static _module Getmodulewithname (String name) {for (_module module:getmodules ()) if (module.ge Ttf_modulename (). Equals (name)) return Module;return null; public static list<_module> GetModules () {return modules;} public static void Setmodules (List<_module> modules) {applicationservice.modules = modules;}}

Add a static variable to the above class to hold all the module, without having to load it in the database every time you request it.

Add this to let the menu group below the menu also execute the SQL statement added, otherwise, to return to MVC to join the menu,//will be executed in SQL because the session is closed and error for (_module module:result.getTf_ Modules ()) {Module.getmodulefields (). Size (); for (_modulegridscheme scheme:module.getModuleGridSchemes ()) {for (_ Modulegridschemegroup group:scheme.getModuleGridSchemeGroups ()) {Group.getmodulegridschemegroupfields (). Size ();}} For (_moduleformscheme scheme:module.getModuleFormSchemes ()) {for (_moduleformschemegroup Group: Scheme.getmoduleformschemegroups ()) {Group.getmoduleformschemegroupfields (). Size ();}}
This paragraph is also newly added, the function is that the session is not closed before the data of the various sub-modules are read in.

After adding the action, we refresh the page, and in the definition of module _modulegroup, we add the fields and lists and the form scheme.



Too tired, sweating!


The following began to extjs5 to deal with the data from the background.


Learn Extjs5 with me. (35--design of individual modules [3 automatically generate data based on class annotations])

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.