package cn.edu.hpu.tax.info.entity; import java.io.Serializable; import java.sql.Timestamp; import 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; //状态 public static String INFO_STATE_PUBLIC = "1";//发布 public static String INFO_STATE_STOP = "0";//停用 //信息分类 public static String INFO_TYPE_TZGG="tzgg"; public static String INFO_TYPE_ZCSD="zcsd"; public static String INFO_TYPE_NSZD="nszd"; public static Map<String,String> INFO_TYPE_MAP; static{ INFO_TYPE_MAP=new HashMap<String,String>(); INFO_TYPE_MAP.put(INFO_TYPE_TZGG, "通知公告"); INFO_TYPE_MAP.put(INFO_TYPE_ZCSD, "政策速递"); INFO_TYPE_MAP.put(INFO_TYPE_NSZD, "纳税指导"); } public Info(){ } public Info(String infoId, String type, String source, String title, String content, String memo, String creator, Timestamp createTime, String state) { super(); this.infoId = infoId; this.type = type; this.source = source; this.title = title; this.content = content; this.memo = memo; this.creator = creator; this.createTime = createTime; this.state = state; } //下面是get和set方法,这里省略 }
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="cn.edu.hpu.tax.info.entity.Info" table="info"> <id name="infoId" type="java.lang.String"> <column name="info_id" length="32"/> <generator class="uuid.hex" /> </id> <property name="type" type="java.lang.String"> <column name="type" length="10" /> </property> <property name="source" type="java.lang.String"> <column name="source" length="50" /> </property> <property name="title" type="java.lang.String"> <column name="title" length="100" not-null="true" /> </property> <property name="content" type="text"> <column name="content" /> </property> <property name="memo" type="java.lang.String"> <column name="memo" length="200" /> </property> <property name="creator" type="java.lang.String"> <column name="creator" length="10" /> </property> <property name="createTime" type="java.sql.Timestamp"> <column name="create_time" length="19" /> </property> <property name="state" type="java.lang.String"> <column name="state" length="1" /> </property> </class> </hibernate-mapping>
package cn.edu.hpu.tax.info.dao; import cn.edu.hpu.tax.core.dao.BaseDao; import cn.edu.hpu.tax.info.entity.Info; public interface InfoDao extends BaseDao<Info> { }
package cn.edu.hpu.tax.info.dao.impl; import cn.edu.hpu.tax.core.dao.impl.BaseDaoImpl; import cn.edu.hpu.tax.info.dao.InfoDao; import cn.edu.hpu.tax.info.entity.Info; public class InfoDaoImpl extends BaseDaoImpl<Info> implements InfoDao { }
package cn.edu.hpu.tax.info.service; import java.io.Serializable; import java.util.List; import cn.edu.hpu.tax.info.entity.Info; public interface InfoService { //新增 public void save(Info entity); //更新 public void update(Info enetity); //根据id删除 public void delete(Serializable id); //根据id查找 public Info findObjectById(Serializable id); //查找列表 public List<Info> findObjects(); }
package cn.edu.hpu.tax.info.service.impl; import java.io.Serializable; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import cn.edu.hpu.tax.info.dao.InfoDao; import cn.edu.hpu.tax.info.entity.Info; @Service("infoService") public class InfoServiceImpl implements InfoService { @Resource private InfoDao infoDao; @Override public void delete(Serializable id) { infoDao.delete(id); } @Override public Info findObjectById(Serializable id) { return infoDao.findObjectById(id); } @Override public List<Info> findObjects() { return infoDao.findObjects(); } @Override public void save(Info entity) { infoDao.save(entity); } @Override public void update(Info enetity) { infoDao.update(enetity); } }
package cn.edu.hpu.tax.info.action; import java.util.HashSet; import java.util.List; import javax.annotation.Resource; import cn.edu.hpu.tax.core.action.BaseAction; import cn.edu.hpu.tax.core.content.Constant; import cn.edu.hpu.tax.info.entity.Info; import cn.edu.hpu.tax.info.service.InfoService; import com.opensymphony.xwork2.ActionContext; public class InfoAction extends BaseAction { @Resource private InfoService infoService; private List<Info> infoList; private Info info; //列表页面 public String listUI() throws Exception{ try { //加载分类集合 ActionContext.getContext().getContextMap().put("infoTypeMap", Info.INFO_TYPE_MAP); infoList=infoService.findObjects(); } catch (Exception e) { throw new Exception(e.getMessage()); } return "listUI"; } //跳转到新增页面 public String addUI(){ //加载分类集合 ActionContext.getContext().getContextMap().put("infoTypeMap", Info.INFO_TYPE_MAP); //在进入编辑页面的时候传入当前创建时间 info=new Info(); info.setCreateTime(new Timestamp(new Date().getTime())); return "addUI"; } //保存新增 public String add(){ if(info!=null ){ infoService.save(info); } return "list"; } //跳转到编辑界面 public String editUI(){ //加载分类集合 ActionContext.getContext().getContextMap().put("infoTypeMap", Info.INFO_TYPE_MAP); if(info!=null && info.getInfoId()!=null){ info=infoService.findObjectById(info.getInfoId()); } return "editUI"; } //保存编辑 public String edit(){ infoService.update(info); return "list"; } //删除 public String delete(){ if(info!=null && info.getInfoId()!=null){ infoService.delete(info.getInfoId()); } return "list"; } //批量删除 public String deleteSelected(){ if(selectedRow!=null){ for(String id:selectedRow){ infoService.delete(id); } } return "list"; } public List<Info> getInfoList() { return infoList; } public void setInfoList(List<Info> InfoList) { this.infoList = InfoList; } public Info getInfo() { return info; } public void setInfo(Info info) { this.info = info; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 继承了注入sessionFactory的抽象类,不用反复出入sessionFactory --> <bean id="infoDao" class="cn.edu.hpu.tax.info.dao.impl.InfoDaoImpl" parent="xDao"></bean> <!-- 扫描Service --> <context:component-scan base-package="cn.edu.hpu.tax.info.service.impl"></context:component-scan> </beans>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="info-action" namespace="/tax" extends="base-default"> <action name="info_*" class="cn.edu.hpu.tax.info.action.InfoAction" method="{1}"> <result name="{1}">/WEB-INF/jsp/tax/info/{1}.jsp</result> <result name="list" type="redirectAction"> <param name="actionName">info_listUI</param> </result> </action> </package> </struts>
<!-- 信息发布的struts配置文件 --> <include file="cn/edu/hpu/tax/info/conf/info-struts.xml"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>信息发布管理</title> <script type="text/javascript"> //全选、全反选 function doSelectAll(){ // jquery 1.6 前 //$("input[name=selectedRow]").attr("checked", $("#selAll").is(":checked")); //prop jquery 1.6+建议使用 $("input[name=selectedRow]").prop("checked", $("#selAll").is(":checked")); } //新增 function doAdd(){ document.forms[0].action = "${basePath}tax/info_addUI.action"; document.forms[0].submit(); } //编辑 function doEdit(id){ document.forms[0].action = "${basePath}tax/info_editUI.action?info.infoId=" + id; document.forms[0].submit(); } //删除 function doDelete(id){ document.forms[0].action = "${basePath}tax/info_delete.action?info.infoId=" + id; document.forms[0].submit(); } //批量删除 function doDeleteAll(){ document.forms[0].action = "${basePath}tax/info_deleteSelected.action"; document.forms[0].submit(); } </script> </head> <body class="rightBody"> <form name="form1" action="" method="post"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>信息发布管理</strong></div> </div> <div class="search_art"> <li> 信息标题:<s:textfield name="info.title" cssClass="s_text" id="infoTitle" cssStyle="width:160px;"/> </li> <li><input type="button" class="s_button" value="搜 索" onclick="doSearch()"/></li> <li style="float:right;"> <input type="button" value="新增" class="s_button" onclick="doAdd()"/> <input type="button" value="删除" class="s_button" onclick="doDeleteAll()"/> </li> </div> <div class="t_list" style="margin:0px; border:0px none;"> <table width="100%" border="0"> <tr class="t_tit"> <td width="30" align="center"><input type="checkbox" id="selAll" onclick="doSelectAll()" /></td> <td align="center">信息标题</td> <td width="120" align="center">信息分类</td> <td width="120" align="center">创建人</td> <td width="140" align="center">创建时间</td> <td width="80" align="center">状态</td> <td width="120" align="center">操作</td> </tr> <s:iterator value="infoList" status="st"> <tr <s:if test="#st.odd"> bgcolor="f8f8f8" </s:if> > <td align="center"><input type="checkbox" name="selectedRow" value="<s:property value='infoId'/>"/></td> <td align="center"><s:property value="title"/></td> <td align="center"> <s:property value="#infoTypeMap[type]"/> </td> <td align="center"><s:property value="creator"/></td> <td align="center"><s:date name="createTime" format="yyyy-MM-dd HH:mm"/></td> <td id="show_<s:property value='infoId'/>" align="center"><s:property value="state==1?'发布':'停用'"/></td> <td align="center"> <a href="#">停用</a> <a href="javascript:doEdit('<s:property value='infoId'/>')">编辑</a> <a href="javascript:doDelete('<s:property value='infoId'/>')">删除</a> </td> </tr> </s:iterator> </table> </div> </div> <div class="c_pate" style="margin-top: 5px;"> <table width="100%" class="pageDown" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right"> 总共1条记录,当前第 1 页,共 1 页 <a href="#">上一页</a> <a href="#">下一页</a> 到 <input type="text" style="width: 30px;" onkeypress="if(event.keyCode == 13){doGoPage(this.value);}" min="1" max="" value="1" /> </td> </tr> </table> </div> </div> </div> </form> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>信息发布管理</title> <script> </script> </head> <body class="rightBody"> <form id="form" name="form" action="${basePath }tax/info_add.action" method="post" enctype="multipart/form-data"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>信息发布管理</strong> - 新增信息</div></div> <div class="tableH2">新增信息</div> <table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0" > <tr> <td class="tdBg" width="200px">信息分类:</td> <td><s:select name="info.type" list="#infoTypeMap"/></td> <td class="tdBg" width="200px">来源:</td> <td><s:textfield name="info.source"/></td> </tr> <tr> <td class="tdBg" width="200px">信息标题:</td> <td colspan="3"><s:textfield name="info.title" cssStyle="width:90%"/></td> </tr> <tr> <td class="tdBg" width="200px">信息内容:</td> <td colspan="3"><s:textarea id="editor" name="info.content" cssStyle="width:90%;height:160px;" /></td> </tr> <tr> <td class="tdBg" width="200px">备注:</td> <td colspan="3"><s:textarea name="info.memo" cols="90" rows="3"/></td> </tr> <tr> <td class="tdBg" width="200px">创建人:</td> <td> <s:property value="#session.SYS_USER.name"/> <s:hidden name="info.creator" value="%{#session.SYS_USER.name}"/> </td> <td class="tdBg" width="200px">创建时间:</td> <td> <s:date name="info.createTime" format="yyyy-MM-dd HH:mm"/> <s:hidden name="info.createTime"/> </td> </tr> </table> <!-- 默认信息状态为 发布 --> <s:hidden name="info.state" value="1"/> <div class="tc mt20"> <input type="submit" class="btnB2" value="保存" /> <input type="button" onclick="javascript:history.go(-1)" class="btnB2" value="返回" /> </div> </div></div></div> </form> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>信息发布管理</title> <script> </script> </head> <body class="rightBody"> <form id="form" name="form" action="${basePath}tax/info_edit.action" method="post" enctype="multipart/form-data"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>信息发布管理</strong> - 修改信息</div></div> <div class="tableH2">修改信息</div> <table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0" > <tr> <td class="tdBg" width="200px">信息分类:</td> <td><s:select name="info.type" list="#infoTypeMap"/></td> <td class="tdBg" width="200px">来源:</td> <td><s:textfield name="info.source"/></td> </tr> <tr> <td class="tdBg" width="200px">信息标题:</td> <td colspan="3"><s:textfield name="info.title" cssStyle="width:90%"/></td> </tr> <tr> <td class="tdBg" width="200px">信息内容:</td> <td colspan="3"><s:textarea id="editor" name="info.content" cssStyle="width:90%;height:160px;" /></td> </tr> <tr> <td class="tdBg" width="200px">备注:</td> <td colspan="3"><s:textarea name="info.memo" cols="90" rows="3"/></td> </tr> <tr> <td class="tdBg" width="200px">创建人:</td> <td> <s:property value="info.creator"/> <s:hidden name="info.creator"/> </td> <td class="tdBg" width="200px">创建时间:</td> <td> <s:date name="info.createTime" format="yyyy-MM-dd HH:mm"/> <s:hidden name="info.createTime"/> </td> </tr> </table> <s:hidden name="info.infoId"/> <s:hidden name="info.state"/> <div class="tc mt20"> <input type="submit" class="btnB2" value="保存" /> <input type="button" onclick="javascript:history.go(-1)" class="btnB2" value="返回" /> </div> </div></div></div> </form> </body> </html>
<dl> <dt><a class="xxfb" href="${ctx }tax/info_listUI.action" target="mainFrame"><b></b>信息发布管理<s class="down"></s> </a></dt> </dl>
至此我们信息发布管理的基础增删改查完成了,但是我们还没有完成我们的所有需求,下一篇总结继续完成我们的信息发布管理业务的功能。
转载请注明出处:http://blog.csdn.net/acmman/article/details/49700015