跟我一起學extjs5(30--加入模組和菜單定義[3後台系統資料的組織和產生]),extjs530--

來源:互聯網
上載者:User

跟我一起學extjs5(30--加入模組和菜單定義[3後台系統資料的組織和產生]),extjs530--
跟我一起學extjs5(30--加入模組和菜單定義[3後台系統資料的組織和產生])
        對於大多web程式來說,後台是完成控制和處理的,前台就是一個展示工具,這個系統也是這樣。在上一節中建立了四個模組,下面開始設計前背景互動。將系統資訊和模組、菜單資訊傳到前台,由前台來進行展示。        首先建立一個java bean類用來存放各種需要傳到前台的資料,裡麵包括:系統資訊、操作人員資訊、服務人員資訊、模組資訊、菜單。現在只加入了這幾個,以後還要加入各種 各樣的使用權限設定。在com.jfok.server.common中新增包info,在這下面加入四個class。

package com.jfok.server.common.info;import java.io.Serializable;@SuppressWarnings("serial")// 這是服務單位情況的設定,也是放在資料庫裡的,可以進行修改public class ServiceInfo implements Serializable {private String tf_serviceDepartment;// 服務單位private String tf_serviceMen;// 服務人員private String tf_serviceTelnumber;// 聯絡電話private String tf_serviceFaxnumber;// 傳真private String tf_serviceEmail;// 電子郵件private String tf_serviceHomepage;// 首頁private String tf_serviceQQ;// QQ號private String tf_copyrightOwner;// 著作權單位private String tf_copyrightInfo;// 著作權資訊public ServiceInfo() {}}

package com.jfok.server.common.info;import java.io.Serializable;@SuppressWarnings("serial")// 這是系統總體情況的設定,也是放在資料庫裡的,可以進行修改public class SystemInfo implements Serializable {private String tf_systemName; // 系統名稱private String tf_systemVersion; // 版本號碼private String tf_systemAddition;// 附加設定public SystemInfo() {}}

import java.io.Serializable;import java.util.Date;@SuppressWarnings("serial")// 這是使用者單位和登入使用者的資訊public class UserInfo implements Serializable {private String tf_userdwmc;// 使用單位名稱private Date tf_userStartdate;// 開始使用時間private Integer tf_userId;// 使用者idprivate String tf_loginName;// 使用者登入名稱private String tf_userName;// 使用者姓名private String tf_departmentId = null;// 使用者部門idprivate String tf_departmentName = null;// 使用者部門名稱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;/** * 用於向用戶端返回系統的模組資訊和登入人員的資訊的類 *  * @author jfok *  */@SuppressWarnings("serial")@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)public class ApplicationInfo implements Serializable {// 這是系統總體情況的設定,也是放在資料庫裡的,可以進行修改private SystemInfo systemInfo;// 這是使用者單位和登入使用者的資訊private UserInfo userInfo;// 這是服務單位情況的設定,也是放在資料庫裡的,可以進行修改private ServiceInfo serviceInfo;// 系統中模組的字義和菜單的定義private Set<_Module> tf_Modules; // 系統模組定義資訊private List<_MenuGroup> tf_MenuGroups; // 系統功能表// 系統中各種許可權的定義// 其他一些附加資訊需要傳送到前台的private Integer tf_additionFileMaxMB; // 上傳檔案的最大大小private String tf_previewExts; // 可預覽的檔案的尾碼名 ,用逗號分開public ApplicationInfo() {}}

        以上類的getter和setter全部自己加一下。
        繼續在com.jfok.server.service中新增一個類用來產生資料的服務類 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;// 事務注釋@SuppressWarnings("unchecked")@Transactional(propagation = Propagation.REQUIRED, readOnly = true)public ApplicationInfo getApplicationInfo(HttpServletRequest request) {ApplicationInfo result = new ApplicationInfo();// 以上內容暫時為自訂的,以後會改為從資料庫和登入資訊中讀取。SystemInfo systemInfo = new SystemInfo();systemInfo.setTf_systemName("自訂的中小型管理系統");systemInfo.setTf_systemVersion("2014.09.28");result.setSystemInfo(systemInfo);UserInfo userInfo = new UserInfo();userInfo.setTf_userdwmc("無錫市宏宇電子有限公司");userInfo.setTf_userStartdate(new Date());userInfo.setTf_userName("管理員");userInfo.setTf_loginName("admin");userInfo.setTf_userId(0);userInfo.setTf_departmentId("00");userInfo.setTf_departmentName("工程部");result.setUserInfo(userInfo);ServiceInfo serviceInfo = new ServiceInfo();serviceInfo.setTf_serviceDepartment("熙旺公司");serviceInfo.setTf_serviceMen("蔣鋒");serviceInfo.setTf_serviceTelnumber("1320528xxxx");serviceInfo.setTf_serviceFaxnumber("0510-88888888");serviceInfo.setTf_serviceQQ("7858xxxx");serviceInfo.setTf_serviceEmail("jfok1972@qq.com");serviceInfo.setTf_serviceHomepage("www.www.net");serviceInfo.setTf_copyrightInfo("熙旺公司著作權");serviceInfo.setTf_copyrightOwner("熙旺軟體");result.setServiceInfo(serviceInfo);// 把所有的模組定義資訊加進去result.setTf_Modules(new HashSet<_Module>((List<_Module>) systemBaseDAO.findAll(_Module.class)));// 加入菜單分組result.setTf_MenuGroups((List<_MenuGroup>) systemBaseDAO.findAll(_MenuGroup.class));for (_MenuGroup mg : result.getTf_MenuGroups()) {// 加入這一條是為了讓菜單組下面的菜單也執行sql 語句加進來,不然的話,返回以後mvc要加入菜單,// 就會在執行sql的時候因為session已經關閉而報錯mg.getTf_menuModules().size();}return result;}}

        在上面用到了DAO類,我自己做了一個系統的基本DAO類接品和類,放在包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;}}

        最後加入spring MVC的控制類,在com.jfok.server.controller中新增一個類ApplicationController.java:
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注釋,自動注入ApplicationService 的執行個體@Resourceprivate ApplicationService applicationService;@RequestMapping("/applicationinfo.do")public synchronized @ResponseBodyApplicationInfo getApplicationInfo(HttpServletRequest request) {return applicationService.getApplicationInfo(request);}}

        加好這幾個檔案後的圖示為:










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.