In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces SSH how to achieve information release management, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The development of information release is still carried out from entity- > dao- > service- > action- > config.
Here are a few points of knowledge:
(1) for the big data quantitative text field in the form, its type should use text in the mapping file (* .hbm.xml).
For example: in Java file
Private String content
In the Hibernate mapping file
(2) understanding of Date, Calendar and Timstamp
In the Java file
Private Timestamp createTime
In the Hibernate mapping file
(3) extract BaseService
(4) on the new page, display the current time
Java code
Info = new Info (); info.setCreateTime (new Timestamp (new Date (). GetTime (); / / to show the current time on the page
Display the struts tag of the time in the JSP page
(5) the id value of the HTML tag combined with the use of the primary key in the database, so that the id value of the HTML tag will not be repeated.
1. Entity layer
Info.java
Package com.rk.tax.entity;import java.io.Serializable;import java.sql.Timestimport java.util.HashMap;import java.util.Map;public class Info implements Serializable {private String infoId; private String type; private String source; private String title; private String content; private String memo; private String creator; private Timestamp createTime; private String state / / status public static String INFO_STATE_PUBLIC = "1"; / / publish public static String INFO_STATE_STOP = "0"; / / deactivate / / Information Classification public static String INFO_TYPE_TZGG = "tzgg"; public static String INFO_TYPE_ZCSD = "zcsd"; public static String INFO_TYPE_NSZD = "nszd"; public static Map INFO_TYPE_MAP Static {INFO_TYPE_MAP = new HashMap (); INFO_TYPE_MAP.put (INFO_TYPE_TZGG, "notice notice"); INFO_TYPE_MAP.put (INFO_TYPE_ZCSD, "Policy Express"); INFO_TYPE_MAP.put (INFO_TYPE_NSZD, "tax guidance") } / / {{public String getInfoId () {return infoId;} public void setInfoId (String infoId) {this.infoId = infoId;} public String getType () {return type;} public void setType (String type) {this.type = type } public String getSource () {return source;} public void setSource (String source) {this.source = source;} public String getTitle () {return title;} public void setTitle (String title) {this.title = title } public String getContent () {return content;} public void setContent (String content) {this.content = content;} public String getMemo () {return memo;} public void setMemo (String memo) {this.memo = memo } public String getCreator () {return creator;} public void setCreator (String creator) {this.creator = creator;} public Timestamp getCreateTime () {return createTime;} public void setCreateTime (Timestamp createTime) {this.createTime = createTime } public String getState () {return state;} public void setState (String state) {this.state = state;} / /}
Info.hbm.xml
2. Dao layer
InfoDao.java
Package com.rk.tax.dao;import com.rk.core.dao.BaseDao;import com.rk.tax.entity.Info;public interface InfoDao extends BaseDao {}
InfoDaoImpl.java
Package com.rk.tax.dao.impl;import com.rk.core.dao.impl.BaseDaoImpl;import com.rk.tax.dao.InfoDao;import com.rk.tax.entity.Info;public class InfoDaoImpl extends BaseDaoImpl implements InfoDao {}
For more information about BaseDao and BaseDaoImpl, please see http://lsieun.blog.51cto.com/9210464/1835776.
3. Service layer
Here we will extract a generic Service, that is, BaseService.
BaseService.java
Package com.rk.core.service;import java.io.Serializable;import java.util.List;public interface BaseService {/ / add public void save (T entity); / / update public void update (T entity); / / delete public void delete (Serializable id) according to id; / / find public T findById (Serializable id) based on id / / find list public List findAll ();}
BaseServiceImpl.java although the corresponding operation is completed through baseDao here, you should provide baseDao with a specific instance variable to perform the operation, otherwise a null exception will be reported. In this project, all dao and service are managed by Spring's IOC container, so how do you get Spring's IOC container to inject baseDao into BaseServiceImpl? Answer: the injection is done through a subclass of BaseServiceImpl.
Package com.rk.core.service.Impl;import java.io.Serializable;import java.util.List;import com.rk.core.dao.BaseDao;import com.rk.core.service.BaseService;public class BaseServiceImpl implements BaseService {private BaseDao baseDao; public void setBaseDao (BaseDao baseDao) {this.baseDao = baseDao;} public void save (T entity) {baseDao.save (entity) } public void update (T entity) {baseDao.update (entity);} public void delete (Serializable id) {baseDao.delete (id);} public T findById (Serializable id) {return baseDao.findById (id);} public List findAll () {return baseDao.findAll () }}
InfoService.java
Package com.rk.tax.service;import com.rk.core.service.BaseService;import com.rk.tax.entity.Info;public interface InfoService extends BaseService {}
Note to InfoServiceImpl.java: here the injection of baseDao is completed simultaneously through the injection of infoDao.
Package com.rk.tax.service.impl;import javax.annotation.Resource;import org.springframework.stereotype.Service;import com.rk.core.service.Impl.BaseServiceImpl;import com.rk.tax.dao.InfoDao;import com.rk.tax.entity.Info;import com.rk.tax.service.InfoService;@Service ("infoService") public class InfoServiceImpl extends BaseServiceImpl implements InfoService {private InfoDao infoDao; @ Resource public void setInfoDao (InfoDao infoDao) {setBaseDao (infoDao) This.infoDao = infoDao;}}
4. Action layer
InfoAction.java
Package com.rk.tax.action;import java.sql.Timestimport java.util.Date;import java.util.List;import javax.annotation.Resource;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import com.opensymphony.xwork2.ActionContext;import com.rk.core.action.BaseAction;import com.rk.tax.entity.Info;import com.rk.tax.service.InfoService @ Controller ("infoAction") @ Scope ("prototype") public class InfoAction extends BaseAction {/ * 1, business data * / private List infoList; private Info info; / * 2, business implementation class * / @ Resource private InfoService infoService / * 3. Response to the operation of the JSP page * / / list page public String listUI () {/ / load category collection ActionContext.getContext (). GetContextMap (). Put ("infoTypeMap", Info.INFO_TYPE_MAP); infoList = infoService.findAll (); return "listUI" } / / Jump to the new page public String addUI () {/ / load the category collection ActionContext.getContext (). GetContextMap (). Put ("infoTypeMap", Info.INFO_TYPE_MAP); info = new Info (); info.setCreateTime (new Timestamp (new Date (). GetTime () / / to display the current time return "addUI" on the page;} / / Save the new public String add () {if (info! = null) {infoService.save (info);} return "list" } / / Jump to the edit page public String editUI () {/ / load the category collection ActionContext.getContext (). GetContextMap (). Put ("infoTypeMap", Info.INFO_TYPE_MAP) If (info! = null & & info.getInfoId ()! = null) {info = infoService.findById (info.getInfoId ());} return "editUI" } / / Save and edit public String edit () {if (info! = null) {infoService.update (info);} return "list" } / / Delete public String delete () {if (info! = null & & info.getInfoId ()! = null) {infoService.delete (info.getInfoId ());} return "list" } / / batch delete public String deleteSelected () {if (selectedRow! = null) {for (String id: selectedRow) {infoService.delete (id);}} return "list" } / / Asynchronous release information public void publicInfo () {try {if (info! = null & & info.getInfoId ()! = null) {/ / 1, update message status Info temp = infoService.findById (info.getInfoId ()) Temp.setState (info.getState ()); infoService.update (temp); / / 2. Output update result HttpServletResponse response = ServletActionContext.getResponse () Response.setContentType ("text/html"); ServletOutputStream outputStream = response.getOutputStream (); outputStream.write ("update status successful" .getBytes ("utf-8")); outputStream.close () }} catch (Exception e) {e.printStackTrace ();}} / {{public List getInfoList () {return infoList;} public void setInfoList (List infoList) {this.infoList = infoList } public Info getInfo () {return info;} public void setInfo (Info info) {this.info = info;} / /}
5 、 config
(1) entity layer configuration
Is the mapping file of Hibernate
(2) dao layer configuration, which injects dao into the IOC container of Spring
(3) service layer configuration, which is to inject service into the IOC container of Spring
(4) action layer configuration, one is to inject action into the IOC container of Spring, and the other is to map action to url in struts.
(5) finally, all configurations are saved and summarized into applicationContext and struts.xml.
6. Front desk JSP page
6.1 、 listUI.jsp
Information release management / / Select all, select all inverted function doSelectAll () {/ / jquery 1.6before / / $("input [name=selectedRow]") .attr ("checked", $("# selAll") .is (": checked")) / / prop jquery 1.6 + recommended $("input [name=selectedRow]") .prop ("checked", $("# selAll") .is (": checked"));} / / add function doAdd () {document.forms [0] .action = "${basePath} / tax/info_addUI.action" Document.forms [0] .submit ();} / Edit function doEdit (id) {document.forms [0] .action = "${basePath} / tax/info_editUI.action?info.infoId=" + id; document.forms [0] .submit () } / / Delete function doDelete (id) {document.forms [0] .action = "${basePath} / tax/info_delete.action?info.infoId=" + id; document.forms [0] .submit () } / / batch delete function doDeleteAll () {document.forms [0] .action = "${basePath} / tax/info_deleteSelected.action"; document.forms [0] .submit () } / / asynchronously publish information, the id of the message and the information status to be changed to function doPublic (infoId, state) {/ / 1, update message status $.ajax ({url: "${basePath} / tax/info_publicInfo.action") Data: {"info.infoId": infoId, "info.state": state}, type: "post" Success:function (msg) {/ / 2, update the status bar, The display value of the operation bar if ("update status successful" = = msg) {if (state = = 1) {/ / indicates that the information status has been changed to publish. The status bar displays the publication, and the action bar shows deactivating $('# show_'+infoId) .html ("publish") $('# oper_'+infoId) .html ('deactivate') } else {$('# show_'+infoId) .html ("deactivate") $('# oper_'+infoId) .html ('publish') }} else {alert ("failed to update information status!") ;}}, error:function () {alert ("failed to update information status!") ;}) } Information release management information title: letter Information title information classification creator creates time status operation Deactivate Publish Edit deletion Total 1 record Current page 1, a total of 1 page previous page to the next page
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.