咱们如今来到了纳税服务系统的信息发布管理模块,首先咱们跟着原型图来进行需求分析把:javascript
一些普通的CRUD,值得一作的就是状态之间的切换了。停用和发布切换。
css
值得注意的是:在信息内容中,它能够带格式地复制内容,而后上传到咱们的服务器中。html
流程图:前端
package zhongfucheng.info.entity; import java.sql.Timestamp; import java.util.HashMap; import java.util.Map; public class Info implements java.io.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 = new HashMap<String, String>(); static { 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 title) { this.title = title; } public Info(String type, String source, String title, String content, String memo, String creator, Timestamp createTime, String state) { this.type = type; this.source = source; this.title = title; this.content = content; this.memo = memo; this.creator = creator; this.createTime = createTime; this.state = state; } public String getInfoId() { return this.infoId; } public void setInfoId(String infoId) { this.infoId = infoId; } public String getType() { return this.type; } public void setType(String type) { this.type = type; } public String getSource() { return this.source; } public void setSource(String source) { this.source = source; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public String getContent() { return this.content; } public void setContent(String content) { this.content = content; } public String getMemo() { return this.memo; } public void setMemo(String memo) { this.memo = memo; } public String getCreator() { return this.creator; } public void setCreator(String creator) { this.creator = creator; } public Timestamp getCreateTime() { return this.createTime; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } public String getState() { return this.state; } public void setState(String state) { this.state = state; } }
package zhongfucheng.info.entity; import java.sql.Timestamp; import java.util.HashMap; import java.util.Map; public class Info implements java.io.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 = new HashMap<String, String>(); static { 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 title) { this.title = title; } public Info(String type, String source, String title, String content, String memo, String creator, Timestamp createTime, String state) { this.type = type; this.source = source; this.title = title; this.content = content; this.memo = memo; this.creator = creator; this.createTime = createTime; this.state = state; } public String getInfoId() { return this.infoId; } public void setInfoId(String infoId) { this.infoId = infoId; } public String getType() { return this.type; } public void setType(String type) { this.type = type; } public String getSource() { return this.source; } public void setSource(String source) { this.source = source; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public String getContent() { return this.content; } public void setContent(String content) { this.content = content; } public String getMemo() { return this.memo; } public void setMemo(String memo) { this.memo = memo; } public String getCreator() { return this.creator; } public void setCreator(String creator) { this.creator = creator; } public Timestamp getCreateTime() { return this.createTime; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } public String getState() { return this.state; } public void setState(String state) { this.state = state; } }
这如今对咱们来讲没有什么难度了,改以前写过的User模块就好了。java
编写dao、编写service、编写action、编写配置文件web
将配置文件加载到总配置文件中。ajax
导入前端的JSP页面sql
弄完以后,简单的增删改查咱们已经实现了。。
数据库
接下来就是处理一些不是经常使用增删改查的东西了。json
咱们在添加的时候怎么写呢???在需求上,不是让咱们填的,而是写死的。
<tr> <td class="tdBg" width="200px">建立人:</td> <td> </td> <td class="tdBg" width="200px">建立时间:</td> <td> </td> </tr>
建立人咱们在Session中找到对应的用户,给出对应的值。显示出来后,在提交的时候还要经过隐藏域把数据带过去
<tr> <td class="tdBg" width="200px">建立人:</td> <td> <s:property value="#session.SYS_USER.name"/> <s:hidden value="#session.SYS_USER.name" 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>
建立时间,咱们能够直接在InfoAction中,new出Info对象,给出对应的值。在JSP页面就能够回显出来了。
固然了,咱们也要经过隐藏域把数据带过去。
public String addUI() { ActionContext.getContext().getContextMap().put("infoTypeMap", Info.INFO_TYPE_MAP); info = new Info(); info.setCreateTime(new Timestamp(new Date().getTime())); return "addUI"; }
!
咱们想要在那个大文本框中,把复制的内容是带有格式的,图片也能够复制过去。普通的textarea是搞不掂的,咱们须要借助别的组件。。咱们用的是Ueditor组件
"imageUrlPrefix": "http://localhost:8080", /* 图片访问路径前缀 */ "imagePathFormat": "/upload/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,能够自定义保存路径和文件名格式 */
<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/ueditor.all.min.js"> </script> <script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/lang/zh-cn/zh-cn.js"></script> <script> //配置ueditor的根路径 var UEDITOR_HOME_URL = "${basePath}js/ueditor/"; var ue = UE.getEditor('editor'); </script>
var ue = UE.getEditor('editor');
中的editor<td colspan="3"><s:textarea id="editor" name="info.content" cssStyle="width:90%;height:160px;" /></td>
富文本框的配置咱们大多数能够在这里修改:
效果:
很奇怪的是,若是单单访问info模块的话,使用是彻底没有问题的。可是在总系统进入到info模块时,富文本框就点击不了:输入会显示输入个数,可是显示不了内容。编辑的时候一样看不到内容。
因而在网上搜了一下:把如下的代码加入到要用到富文本框的JSP页面下就解决掉问题了:
<script> setTimeout(function(){uParse('div', { 'highlightJsUrl':'/ueditor/third-party/SyntaxHighlighter/shCore.js', 'highlightCssUrl':'/ueditor/third-party/SyntaxHighlighter/shCoreDefault.css'}) },300); </script>
参考博文:http://blog.csdn.net/eightwhells/article/details/13314069
最后地,咱们剩下停用与发布这个功能还没完成…
其实就是一个异步信息交互的实现,当用户点击超连接为停用的时候,就到后台把数据更新,把Info的state变成为0,而后将超连接改为发布。
使用opertor前缀+id定位到咱们的span节点中。这确定是独一无二的。
位于iterator内,直接写state判断就好了。
<span id="operator_<s:property value='infoId'/>"> <s:if test="state==1"> <a href="javascript:doPublic('<s:property value='infoId'/>',0)">停用</a> </s:if> <s:else> <a href="javascript:doPublic('<s:property value='infoId'/>',1)">发布</a> </s:else> </span>
注意在拼接字符串的时候,不要有空格………
error:若是出错了,能够提示用户。
function doPublic (infoId,state){ $.ajax( { url: "${basePath}info/info_doPublic.action", data: { "info.infoId": infoId,"info.state": state}, type: "post", success: function (backData) { if ("更新成功" == backData) { if (state == 0) {//若是用户点击的是停用 //将超连接改为发布 $("#operator_"+infoId).html("<a href='javascript:doPublic(\""+infoId+"\",1)'>发布</a>"); //将显示状态改为是停用 $("#show_" + infoId).html("停用"); }else{//用户点击的是发布 //将超连接改为停用 $("#operator_"+infoId).html("<a href='javascript:doPublic(\""+infoId +"\",0)'>停用</a>"); //将显示状态改为是发布 $("#show_" + infoId).html("发布"); } }else { alert("更新失败,稍后重试"); } }, //若是失败了,就提示给用户,不要让用户继续操做了 error:function () { alert("更新失败,稍后重试"); } } ); } </script>
获得用户的id,查询出Info对象的信息,再设置Info对象的属性。
public void doPublic() { try { if (info != null) { //获得用户带过来的id查询出该对象 Info objectById = infoServiceImpl.findObjectById(info.getInfoId()); //设置它的状态 objectById.setState(info.getState()); //调用service更新数据库 infoServiceImpl.update(objectById); //返回数据给浏览器 HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html charset=utf-8"); response.getOutputStream().write("更新成功".getBytes("UTF-8")); } } catch (IOException e) { e.printStackTrace(); } }