Learn Extjs5 with me (30--add modules and menu definitions [3 organization and generation of backend system data])

Source: Internet
Author: User
Tags log log

Learn Extjs5 with me (30--add modules and menu definitions [3 organization and generation of backend system data])
For most Web applications, the background is complete control and processing, the front desk is a display tool, this system is also the case. In the previous section, four modules were created, and the next stage of interaction was started.        The system Information and modules, menu information to the front desk, from the front desk to display. First, a new Java Bean class is used to store a variety of data to be uploaded to the foreground, including: System Information, operator information, service personnel information, module information, menu. Now you are only adding these, and then you have to add a variety of permission settings. Add the package info to the Com.jfok.server.common and add four classes below.
Package Com.jfok.server.common.info;import java.io.Serializable; @SuppressWarnings ("Serial")//This is the setting of the service unit condition, is also placed in the database, can be modified public class ServiceInfo implements Serializable {private String tf_servicedepartment;//service Unit Private String tf_servicemen;//Service person private string tf_servicetelnumber;//contact phone private string tf_servicefaxnumber;//Fax private String tf_serviceemail;//e-mail private string tf_servicehomepage;//home private string tf_serviceqq;//QQ number private string TF _copyrightowner;//Copyright Unit Private String tf_copyrightinfo;//Copyright Information Public serviceinfo () {}}

Package Com.jfok.server.common.info;import java.io.Serializable; @SuppressWarnings ("Serial")//This is the setup of the overall situation of the system, is also placed in the database, you can modify the public class SystemInfo implements Serializable {private string tf_systemname;//system name private string tf_s Ystemversion; Version number private String tf_systemaddition;//additional settings public SystemInfo () {}}

Import Java.io.serializable;import java.util.Date; @SuppressWarnings ("Serial")//This is the information for user units and logged-on users public class UserInfo Implements Serializable {private String tf_userdwmc;//use unit name private date tf_userstartdate;//start using time private Integer tf_ userid;//user Idprivate string tf_loginname;//user logon name private string tf_username;//user name private string tf_departmentid = null ;//User Department idprivate String tf_departmentname = null;//User Department name Public UserInfo () {}}

Package Com.jfok.server.common.info;import Java.io.serializable;import Java.util.list;import java.util.Set;import Org.codehaus.jackson.map.annotate.jsonserialize;import Com.jfok.server.hibernate.system._menugroup;import com.jfok.server.hibernate.system._module;/** * Class for returning the system's module information and login information to the client * * @author JFOK * * * */@SuppressWarnings (" Serial ") @JsonSerialize (include = JsonSerialize.Inclusion.NON_NULL) public class ApplicationInfo implements Serializable {//This is the system's overall situation settings, but also placed in the database, you can modify the private SystemInfo systeminfo;//This is the user unit and the user's information private UserInfo UserInfo ;//This is the setting of the service unit situation, is also placed in the database, you can modify the definition of the module in the private ServiceInfo serviceinfo;//system and the definitions of the menu private set<_module> tf_ Modules; System module definition information private list<_menugroup> tf_menugroups; System menu//The definition of various permissions in the System//Other additional information needs to be transmitted to the front of the private Integer TF_ADDITIONFILEMAXMB; The maximum size of the uploaded file is private String tf_previewexts; The suffix name of the file that can be previewed, separated by commas public applicationinfo () {}}

The above class getter and setter all add themselves.
Continue to add a class in Com.jfok.server.service that is used to generate data for the service class Applicationservice.java:
Package Com.jfok.server.service;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; @Servicepublic class Applicationservice {@Resourceprivate Systembasedao systembasedao;//transaction Comment @suppresswarnings ("unchecked") @ Transactional (propagation = propagation.required, readOnly = true) public ApplicationInfo getapplicationinfo ( HttpServletRequest request) {applicationinfo result = new ApplicationInfo ();//The above content is temporarily custom, and will later be read from the database and login 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 ("All rights reserved by Hee Wang Company"); Serviceinfo.settf_copyrightowner ("Hee Wang Software"); Result.setserviceinfo (serviceinfo);//Add all the module definition information into the result. Settf_modules (New hashset<_module> ((list<_module>) Systembasedao.findall (_Module.class)));// Add menu group Result.settf_menugroups ((list<_menugroup>) Systembasedao.findall (_menugroup.class)); for (_MenuGroup Mg:result.getTf_MenuGroups ()) {//Join this to allow the menu group below to execute the SQL statement as well, otherwise, to return to the MVC to join the menu,// It will be error mg.gettf_menumodules () when executing SQL because the session is closed. Size (); return result;}}

In the above used the DAO class, I made a system of the basic DAO class and class, placed under the package Com.jfok.server.DAO.
Package Com.jfok.server.dao;import Java.util.List, @SuppressWarnings ("Rawtypes") public interface Isystembasedao { public void Save (object record);p ublic void Attachdirty (object record, Object old);p ublic void Delete (object record);p UBL IC Object FindByID (class<?> className, object ID);p ublic object FindByID (String beanclassname, object ID);p ublic Li St Findbyproperty (class<?> className, String propertyname,object value);p ublic Object Findbypropertyfirst (Class <?> className, string propertyname,object value);p ublic List findbystring (class<?> className, String value) ;p ublic list Findbyproperty (string beanclassname, string propertyname,object value);p ublic list Findbypropertywithothercondition (class<?> className, String propertyname,object value, String othercondstring) ;p ublic list Findbylikeproperty (string beanclassname, string propertyname,object value);p ublic list Findbylikepropertywithothercondition (String beanclassname, String propertyname,object value, String othercondstring);p ublic List findbypropertywithothercondition (String beanclassname, String propertyname,object Value, String othercondstring);p ublic List findbypropertyallsort (String beanclassname, String sort,string dir, String pr Opertyname, Object value, String defaultsort,string defaultdir);p ublic List findAll (class<?> className);p ublic List FindAll (string className);p ublic list Findallsort (string beanclassname, String sort, string dir); List Findbypropertyallsort (class<?> className, string Sort, String dir,string propertyname, Object value, String de Faultsort, String DefaultDir);}

Package Com.jfok.server.dao;import Java.io.serializable;import Java.util.list;import Javax.annotation.postconstruct;import Javax.annotation.resource;import Net.sf.ezmorph.object.datemorpher;import Net.sf.json.util.jsonutils;import Org.apache.commons.logging.log;import org.apache.commons.logging.LogFactory; Import Org.hibernate.criteria;import Org.hibernate.session;import Org.hibernate.sessionfactory;import Org.hibernate.criterion.order;import Org.hibernate.criterion.restrictions;import Org.springframework.orm.hibernate3.support.hibernatedaosupport;import org.springframework.stereotype.Repository ; @Repository @suppresswarnings ("Rawtypes") public class Systembasedao extends Hibernatedaosupport implements Isystembasedao {@Resourceprivate sessionfactory mysessionfactory;public static Systembasedao systembasedao;@ postconstructpublic void Injectedsessionfactory () {//system.out.println ("System base DAO Impl injected Sessionfactory" ); Super.setsessionfactory (mysessionfactory); Systembasedao = this;}Public Systembasedao () {super ();//system.out.println ("System base DAO Impl created"); string[] Dateformats = new string[] {"Yyyy-mm-dd"}; Jsonutils.getmorpherregistry (). Registermorpher (New Datemorpher (Dateformats));//system.out.println ("JSON Tobean DataFormats created ");} Private static final Log log = Logfactory.getlog (systembasedao.class); @Overridepublic void Save (Object record) { Gethibernatetemplate (). Save (record), Log.debug ("New record Saved:" + Record.getclass (). Getsimplename () + ":" + Record.tostring ());} @Overridepublic void Attachdirty (object record, object old) {Gethibernatetemplate (). Saveorupdate (record); Log.debug (" Save Record: "+ Record.getclass (). Getsimplename () +": "+ record.tostring ());} @Overridepublic void Delete (Object record) {gethibernatetemplate (). Delete (record); Log.debug ("Delete record:" + Record.getclass (). Getsimplename () + ":" + record.tostring ()); @Overridepublic Object FindByID (class<?> className, object ID) {return FindByID (Classname.getname (), id);} @OverridepUblic Object FindByID (String beanclassname, Object ID) {Object record;try {record = Gethibernatetemplate (). Get ( Beanclassname, Integer.parseint (id.tostring ()));} catch (Exception e) {record = Gethibernatetemplate (). Get (Beanclassname, (Serializable) ID);} Log.debug ("Get record" + Beanclassname + "key:" + ID + ":" + record); return record; @Overridepublic list<?> findAll (class<?> className) {return findAll (Classname.getname ());} @Overridepublic list<?> findAll (String className) {log.debug ("Find all:" + className); String queryString = "from" + Classname;return gethibernatetemplate (). Find (queryString); public void Setmysessionfactory (Sessionfactory mysessionfactory) {this.mysessionfactory = mysessionfactory;} @Overridepublic list<?> Findallsort (String beanclassname, String sort, string dir) {Log.debug ("Find all:" + BEANCLA Ssname + "---sort:" + sort + "--" + dir); String querystring;if (sort = NULL | | sort.length () = = 0) queryString = "from" + Beanclassname + "as MOdel "; elsequerystring =" from "+ Beanclassname +" as model "+" ORDER By "+ sort +" "+ Dir;return Gethibernatetempla Te (). Find (queryString);} @Overridepublic list<?> Findbypropertyallsort (class<?> className, string sort, string dir,string PropertyName, Object value, String defaultsort, String defaultdir) {return Findbypropertyallsort (Classname.getname (), Sort, dir, PropertyName, Value,defaultsort, DefaultDir);} @Overridepublic list<?> Findbypropertyallsort (String beanclassname, string sort, string Dir,string PropertyName, Object value, String defaultsort, String defaultdir) {Log.debug ("Find all:" + beanclassname + "---sort:" + sort + "--" + D IR), if (Propertyname.indexof (".") > 0) return Findbypropertycriteria (beanclassname, Sort, dir, PropertyName, Value, DEFAULTSORT, DefaultDir); String queryString; String otherfilter = ""; if (sort = NULL | | Sort.length () = = 0) {if (DEFAULTSORT! = null) {sort = Defaultsort;dir = DefaultDir;}} if (sort = null | | sort.length () = = 0)queryString = "from" + Beanclassname + "as model where model." + propertyname+ "=" + Otherfilter;elsequerystring = "F Rom "+ Beanclassname +" as model where model. "+ propertyname+" = "+ Otherfilter +" ORDER BY "+ sort +" + dir;// System.out.println (queryString); return Gethibernatetemplate (). Find (queryString, value);} Public list<?> Findbypropertycriteria (string beanclassname, string sort, String dir,string PropertyName, Object Value, String defaultsort, String DefaultDir) {Session session = Getsessionfactory (). Opensession (); Criteria = Session.createcriteria (beanclassname); string[] props = propertyname.split ("\ \"); Criteria Subcriteria = Criteria.createcriteria (Props[0]), Subcriteria.add (Restrictions.eq (props[1), value), if (sort ! = null) {if (dir = = null | |!dir.tolowercase (). Equals ("desc")) Criteria.addorder (ORDER.ASC (sort)); Elsecriteria.addorder (Order.desc (sort));} else if (DEFAULTSORT! = null) {if (DefaultDir = = NULL | |!defaultdir.tolowercase (). Equals ("DesC ")) Criteria.addorder (ORDER.ASC (DEFAULTSORT)); Elsecriteria.addorder (Order.desc (DEFAULTSORT));} list<?> result = Criteria.list (); Session.close (); return result;} @Overridepublic Object Findbypropertyfirst (class<?> className, String PropertyName, object value) {list<?> result = Findbyproperty (ClassName, PropertyName, value); if (result.size () = = 0) return Null;elsereturn result.get (0);} @Overridepublic Object Findbypropertyfirstwithothercondition (class<?> classname,string PropertyName, Object Value, String othercondstring) {list<?> result = Findbypropertywithothercondition (ClassName, PropertyName, value , othercondstring); if (result.size () = = 0) return Null;elsereturn result.get (0);} @Overridepublic list<?> Findbyproperty (class<?> className, String PropertyName, Object value) {return Findbypropertywithothercondition (Classname.getsimplename (), propertyname,value, null);} @Overridepublic list<?> Findbyproperty (String beanclassname, String PropertynamE, Object value) {return findbypropertywithothercondition (Beanclassname, propertyname, value, NULL);} @Overridepublic list<?> findbypropertywithothercondition (class<?> classname,string propertyName, Object Value, String othercondstring) {return findbypropertywithothercondition (Classname.getsimplename (), PropertyName, Value, othercondstring);} @SuppressWarnings ("unchecked") @Overridepublic list<?> findbypropertywithothercondition (String beanclassname , String propertyname, Object value, String othercondstring) {string queryString = "from" + Beanclassname + "as model whe Re model. " + propertyname + "=?"; if (othercondstring! = null && othercondstring.length () > 1) {queryString = queryString + "and (" + otherconds Tring + ")";} list<object> result = Gethibernatetemplate (). Find (queryString, value); Log.debug (String.Format ("Finding%s with property:%s value:%s:record number:%d ", Beanclassname, PropertyName, Value, Result.size ())); return result; @SuppressWarnings("Unchecked") @Overridepublic list<?> findbystring (class<?> className, String value) {String queryString = " From "+ classname.getsimplename () +" as model where "+ value; list<object> result = Gethibernatetemplate (). Find (queryString); Log.debug (String.Format ("Finding%s with String :%s:record number:%d ", Classname.getsimplename (), Value, Result.size ())); return result; @Overridepublic List Findbylikeproperty (String beanclassname, String propertyname, Object value) {return Findbylikepropertywithothercondition (Beanclassname, PropertyName, Value, "");} @Overridepublic List findbylikepropertywithothercondition (String beanclassname,string PropertyName, Object value, String othercondstring) {string queryString = "from" + Beanclassname + "as model where model." + propertyname + "like?"; if (othercondstring! = null && othercondstring.length () > 1) {queryString = queryString + "and (" + otherconds Tring + ")";} list<?> result = Gethibernatetemplate (). Find (QueryString, value); Log.debug (String.Format ("Finding%s with like property:%s value:%s:record number:%d", Beanclassname,pro Pertyname, Value, Result.size ())); return result;}}

Finally, add spring MVC's control class and add a class Applicationcontroller.java to Com.jfok.server.controller:
Package Com.jfok.server.controller;import Javax.annotation.resource;import javax.servlet.http.HttpServletRequest; Import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.bind.annotation.responsebody;import Com.jfok.server.common.info.ApplicationInfo; Import Com.jfok.server.service.ApplicationService; @Controllerpublic class Applicationcontroller {//Spring comment, Example of automatic injection of applicationservice @resourceprivate applicationservice applicationservice; @RequestMapping ("/ Applicationinfo.do ") Public synchronized @ResponseBodyApplicationInfo Getapplicationinfo (HttpServletRequest request {return applicationservice.getapplicationinfo (request);}}

After adding these documents, the following illustrations are:







Learn Extjs5 with me (30--add modules and menu definitions [3 organization and generation of backend system data])

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.