Learn extjs5 with me (30 -- add module and menu Definition [3 Organization and generation of background system data]), extjs530 --

Source: Internet
Author: User

Learn extjs5 with me (30 -- add module and menu Definition [3 Organization and generation of background system data]), extjs530 --
Learn extjs5 with me (30 -- add module and menu Definition [3 Organization and generation of background system data])
For most web programs, the background is controlled and processed, and the foreground is a display tool, as is the system. Four modules are created in the previous section. The interaction between the front and back ends is designed below. Transmit System Information, modules, and menus to the foreground for display. Create a java bean class to store various data that needs to be uploaded to the foreground, including system information, operator information, service personnel information, module information, and menus. Currently, only these permissions are added, and various permission settings will be added later. Add the info package to com. jfok. server. common and add four classes to it.

Package com.jfok.server.common.info; import java. io. serializable; @ SuppressWarnings ("serial") // This is the setting of the service unit, which is also stored in the database. You can modify public class ServiceInfo implements Serializable {private String tf_serviceDepartment; // private String tf_serviceMen; // private String tf_serviceTelnumber; // contact number private String tf_serviceFaxnumber; // Fax private String tf_serviceEmail; // email private String tf_serviceHomepage; // homepage private String tf_serviceQQ; // QQ No. private String tf_copyrightOwner; // All Rights Reserved units private String tf_copyrightInfo; // copyright information public ServiceInfo (){}}

Package com.jfok.server.common.info; import java. io. serializable; @ SuppressWarnings ("serial") // This is the overall situation of the system and is stored in the database. You can modify public class SystemInfo implements Serializable {private String tf_systemName; // system name private String tf_systemVersion; // version private String tf_systemAddition; // additional settings public SystemInfo (){}}

Import java. io. serializable; import java. util. date; @ SuppressWarnings ("serial") // public class UserInfo implements Serializable {private String tf_userdwmc; // use the unit name private Date tf_userStartdate; // start 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 used to return system Module information and login personnel information to the client ** @ author jfok **/@ SuppressWarnings ("serial ") @ JsonSerialize (include = JsonSerialize. permission Sion. NON_NULL) public class ApplicationInfo implements Serializable {// set the overall situation of the system, which is also stored in the database. You can modify private SystemInfo systemInfo; // This is the private UserInfo userInfo of the user unit and the logged-on user; // This is the setting of the service unit and is also stored in the database. You can modify private ServiceInfo serviceInfo; // The Module definition and menu definition in the system are private Set <_ Module> tf_Modules; // The system Module definition information is private List <_ MenuGroup> tf_MenuGroups; // System Menu // definitions of various permissions in the system // other additional information needs to be sent to the private Integer tf_additionFileMaxMB at the front end; // The maximum size of the uploaded file private String tf_previewExts; // The suffix of the file that can be previewed. Use commas to separate public ApplicationInfo (){}}

Add the getter and setter of the above classes.
Add a new class in com. jfok. server. service to generate the data 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 co M.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 annotation @ SuppressWarnings ("unchecked") @ Transactional (propagation = Propagation. REQUIRED, readOnly = true) public ApplicationInfo getApplicationInfo (HttpServletRequest request) {ApplicationInfo result = new ApplicationInfo (); // The preceding content is currently custom, it will be read from the database and login information later. SystemInfo systemInfo = new SystemInfo (); systemInfo. setTf_systemName ("Custom Small and Medium Management Systems"); 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 ("Administrator"); userInfo. setTf_loginName ("admin"); userInfo. setTf_userId (0); userInfo. setTf_departmentId ("00"); userInfo. setTf_departmentName ("Engineering Department"); result. setUserInfo (userInfo); ServiceInfo serviceInfo = new ServiceInfo (); serviceInfo. setTf_serviceDepartment ("xiwang company"); serviceInfo. setTf_serviceMen ("Jiang Feng"); serviceInfo. setTf_serviceTelnumber ("1320528 xxxx"); serviceInfo. setTf_serviceFaxnumber ("0510-88888888"); serviceInfo. setTf_serviceQQ ("7858 xxxx"); serviceInfo. setTf_serviceEmail ("jfok1972@qq.com"); serviceInfo. setTf_serviceHomepage ("www.www.net"); serviceInfo. setTf_copyrightInfo ("xiwang copyright"); serviceInfo. setTf_copyrightOwner ("xiwang software"); result. setServiceInfo (serviceInfo); // Add all module definitions to result. setTf_Modules (new HashSet <_ Module> (List <_ Module>) systemBaseDAO. findAll (_ Module. class); // Add to the menu group result. setTf_MenuGroups (List <_ MenuGroup>) systemBaseDAO. findAll (_ MenuGroup. class); for (_ MenuGroup mg: result. getTf_MenuGroups () {// add this item to make the menu under the menu group also execute the SQL statement. Otherwise, mvc will add the menu after returning the result, // an error mg is reported when the session is closed during SQL Execution. getTf_menuModules (). size () ;}return result ;}}

I used the DAO class above. I made a system's basic DAO class and class, and put it 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);public void attachDirty(Object record, Object old);public void delete(Object record);public Object findById(Class<?> className, Object id);public Object findById(String beanClassName, Object id);public List findByProperty(Class<?> className, String propertyName,Object value);public Object findByPropertyFirst(Class<?> className, String propertyName,Object value);public List findByString(Class<?> className, String value);public List findByProperty(String beanClassName, String propertyName,Object value);public List findByPropertyWithOtherCondition(Class<?> className, String propertyName,Object value , String otherCondString);public List findByLikeProperty(String beanClassName, String propertyName,Object value);public List findByLikePropertyWithOtherCondition(String beanClassName, String propertyName,Object value, String otherCondString);public List findByPropertyWithOtherCondition(String beanClassName, String propertyName,Object value , String otherCondString);public List findByPropertyAllSort(String beanClassName, String sort,String dir, String propertyName, Object value, String defaultSort,String defaultDir);public List findAll(Class<?> className);public List findAll(String className);public List findAllSort(String beanClassName, String sort, String dir);List findByPropertyAllSort(Class<?> className, String sort, String dir,String propertyName, Object value, String defaultSort, 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:" + beanClassName + "---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 getHibernateTemplate().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 + "--" + dir);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 = "from " + 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 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 where model."+ propertyName + "= ?";if (otherCondString != null && otherCondString.length() > 1) {queryString = queryString + " and (" + otherCondString + ")";}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 (" + otherCondString + ")";}List<?> result = getHibernateTemplate().find(queryString, value);log.debug(String.format("finding %s with like property:%s value: %s : record number:%d", beanClassName,propertyName, value, result.size()));return result;}}

Add the control class of spring MVC, and add ApplicationController. java in 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 annotation, automatically injecting the ApplicationService instance @ Resourceprivate ApplicationService applicationService; @ RequestMapping ("/applicationinfo. do ") public synchronized @ ResponseBodyApplicationInfo getApplicationInfo (HttpServletRequest request) {return applicationService. getApplicationInfo (request );}}

The following figure shows how to add these files:










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.