1、
<td class="tc"><%=newsInf.getNewsType()==null?"":newsInf.getNewsType().getNewsTypeName() %></td>
如果有3种newstype的话,会查询3次。
2、
CRUD | methodName | method | 备注 |
select | newsIndexGET | get |
int pageSize = 10; int pageIndex = StringUtil.objtoInt(request.getParameter("pageIndex")); int newsTypeID = StringUtil.objtoInt(request.getParameter("newsTypeID")); String str = request.getParameter("newsTitle"); String newsTitle = ""; if (StringUtil.stringnotNull(str)) { newsTitle = new String(str.getBytes("iso8859-1"), "UTF-8"); } ModelAndView ma = new ModelAndView(); ma.addObject("newsTypeList", newsTypeService.getAllObject()); StringBuffer querybuffer = new StringBuffer("FROM " + NewsInf.class.getSimpleName() + " WHERE 1=1 "); StringBuffer countbuffer = new StringBuffer("SELECT COUNT(NewsID) FROM " + NewsInf.class.getSimpleName() + " WHERE 1=1 "); Map<String, Object> map = new HashMap<String, Object>(); List<Object> countparamList = new ArrayList<Object>(); if (newsTypeID > 0) { querybuffer.append(" AND NewsTypeID=:NewsTypeID"); countbuffer.append(" AND NewsTypeID=?"); map.put("NewsTypeID", newsTypeID); countparamList.add(newsTypeID); } if (StringUtil.stringnotNull(newsTitle)) { querybuffer.append(" AND NewsTitle LIKE :NewsTitle"); countbuffer.append(" AND NewsTitle LIKE ?"); map.put("NewsTitle", "%" + newsTitle + "%"); countparamList.add("%" + newsTitle + "%"); } querybuffer.append(" ORDER BY iszhiding DESC,rank DESC"); Page<NewsInf> newsPage = newsService.findObjectByPageInf(pageSize, pageIndex, querybuffer.toString(), countbuffer.toString(), map, countparamList.toArray()); ma.addObject("newsList", newsPage.getResult()); ma.addObject("pageStr", PageUtil.getPageStr("", pageIndex, newsPage.getSumcount(), pageSize)); ma.addObject("newsTitle", newsTitle == null ? "" : newsTitle); ma.addObject("newsTypeID", newsTypeID); ma.setViewName("news/newsindex"); return ma;
|
update | updateNewsPOST | post |
NewsInf newsInf = newsService.getObjectByObjectid(newsid); StringBuilder strbuilder = new StringBuilder(); int newsTypeID = newsInf.getNewsType().getNewsTypeID(); for (NewsType newsType : newsTypeService.getlmlistbylmtypeandparentid(new Object[] { LMTYPE.HAVELM.getIndex(), LMTYPE.MANYART.getIndex() }, 0)) { strbuilder.append("<option value='" + newsType.getNewsTypeID() + "'"); if (newsTypeID == newsType.getNewsTypeID()) strbuilder.append(" selected='selected' "); strbuilder.append(">" + newsType.getNewsTypeName() + "</option>"); for (NewsType newsType1 : newsTypeService.getlmlistbylmtypeandparentid(new Object[] { LMTYPE.HAVELM.getIndex(), LMTYPE.MANYART.getIndex() }, newsType.getNewsTypeID())) { strbuilder.append("<option value='" + newsType1.getNewsTypeID() + "'"); if (newsTypeID == newsType1.getNewsTypeID()){ strbuilder.append(" selected='selected' "); } strbuilder.append(">---" + newsType1.getNewsTypeName() + "</option>"); } } model.addAttribute("newsTypeList", newsTypeService.getAllObject()); model.addAttribute("newsInf", newsInf); model.addAttribute("operType", "update"); model.addAttribute("newsTypeStr", strbuilder.toString()); return "news/newsedit";
|
add | addNewsGET | get |
StringBuilder strbuilder = new StringBuilder(); int newsTypeID = StringUtil.objtoInt(request.getParameter("newsTypeID")); for (NewsType newsType : newsTypeService.getlmlistbylmtypeandparentid(new Object[] { LMTYPE.HAVELM.getIndex(), LMTYPE.MANYART.getIndex() }, 0)) { strbuilder.append("<option value='" + newsType.getNewsTypeID() + "'"); if (newsTypeID == newsType.getNewsTypeID()) strbuilder.append(" selected='selected' "); strbuilder.append(">" + newsType.getNewsTypeName() + "</option>"); for (NewsType newsType1 : newsTypeService.getlmlistbylmtypeandparentid(new Object[] { LMTYPE.HAVELM.getIndex(), LMTYPE.MANYART.getIndex() }, newsType.getNewsTypeID())) { strbuilder.append("<option value='" + newsType1.getNewsTypeID() + "'"); if (newsTypeID == newsType1.getNewsTypeID()){ strbuilder.append(" selected='selected' "); } strbuilder.append(">---" + newsType1.getNewsTypeName() + "</option>"); } } ModelAndView ma = new ModelAndView(); ma.addObject("newsTypeList", newsTypeService.getAllObject()); ma.addObject("newsInf", new NewsInf()); ma.addObject("operType", "add"); ma.addObject("newsTypeStr", strbuilder.toString()); ma.setViewName("news/newsedit"); return ma;
|
saveNewsPOST | post |
String newsTitle = request.getParameter("newsTitle"); String newsContent = request.getParameter("newsContent"); Timestamp newsDate = DateUtil.getNowTimeStamp(); String linkUrl = request.getParameter("linkUrl"); Integer newsTypeID = StringUtil.objtoInt(request.getParameter("newsTypeID")); String picUrl = request.getParameter("picUrl"); String writerID = "201222"; String operType = request.getParameter("operType"); NewsInf newsInf = null; if (operType.equals("update")) { int newsID = StringUtil.objtoInt(request.getParameter("newsID")); newsInf = newsService.getObjectByObjectid(newsID); System.out.println("newsID:"+newsID); } else newsInf = new NewsInf(); newsInf.setNewsTitle(newsTitle); newsInf.setNewsContent(newsContent); newsInf.setNewsDate(newsDate); newsInf.setLinkUrl(linkUrl); newsInf.setPicUrl(picUrl); newsInf.setTeacherInf(teacherInfService.getObjectByObjectid(writerID)); newsInf.setNewsType(newsTypeService.getObjectByObjectid(newsTypeID)); newsService.saveorupdateObject(newsInf); JSONObject jobj = new JSONObject();// new一个JSON jobj.accumulate("msg", 1); jobj.accumulate("ResCode", "操作成功"); return jobj;
|
|
delete | delNewsInf | post |
//可以同时删除多个,把id放入list
|
zhiding | newszhiding | post |
//根据id获得newsinf
|
newsquxiao | post | 同上 |
总结
model
NewsInf--.class.getSimpleName()(newsinf)
StringUtil--objtoInt DateUtil--getNowTimeStamp() StringBuilder--toString()
new Object[] { LMTYPE.HAVELM.getIndex(), LMTYPE.MANYART.getIndex() }
Page<NewsInf>
PageUtil--getPageStr() 当前页面的分页信息
service
newsSerivice--getObjectByObjectid/SaveorupdateObject/deletebycolname/findObjectByPageInf
newsTypeService--getlmlistbylmtypeandparentid/getAllObject
teacherInfService
common.js
左侧元素的click事件,一般用不上。
validateForm.js
以后不用了
3、table tr 上下移动
var $up = $('.up'); $up.click(function(){ var $tr = $(this).parents('tr'); if($tr.index != 0){ $tr.fadeOut().fadeIn(); $tr.prev().before($tr); } }) var $down = $('.down'); $down.click(function(){ var $tr = $(this).parents('tr'); if($tr.index != 0){ $tr.fadeOut().fadeIn(); $tr.next().after($tr); } })
学到的知识
1、生成静态页面,再输出,这样不用在页面中设置权限。对于小项目来说,比较方便一点
2、如果返回的栏目条数不固定,就不同jstl了,直接js处理。设想的是,先加载html,css,js,再填充数据;但是对于html不固定的情况,就只能部分加载了
3、form type="submit"之后,怎么获取返回的内容?我一般会用 手动提交,success之后,还需要(看看jquery-validate),阻止form的默认提交。
4、update提交出错。后台能看到数据,数据库中也有更新,但是ajax返回error,需要在ajax中设置async: false;
5、model中验证时,引入import org.hibernate.validator.constraints.NotEmpty;很容易引错了。
6、ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:87)
//网上说是因为不支持substr,可我也没找到有substr的地方
解决办法:
if (StringUtil.stringnotNull(str)) {
newsTitle = new String(str.getBytes("iso8859-1"), "UTF-8");
}
本项目的知识
之前的做法:通过ajax,后端返回html(jstl, jsp),js,html()到container:这样container中会有<script> 现在的做法:通过ajax,后端返回html(jstl, jsp),js,html()到container,把js单独写入frames.jsp的<script>
question1:为什么不把HTML全部一次性写入frames.jsp中?因为html是动态变化的,比如list。
question2:为什么不把frames.jsp的<script>单独写成frames.js?因为<script>中得url需要refer的路径,js文件中,获取不到合适的(host+project)url,而在jsp中,通过request.getContentPath()获取
question3:为什么后端生成的html不用jstl?因为之前用jsp写好了,而且两者也差不多,所以不用换了
manage/index/--frames.jsp--loadmenu/loadpage/loadeditor 得各自写一个方法,注释写清楚。
newsType会有两级,所以,查找type是,for循环嵌套for循环
命名规范
router | method | view | other |
index/ | manageIndex | frames | |
jyxtmenu | jyxMenuGET | jyxtmenu | |
newsindex | newsIndexGET | newsindex | |
newsadd | newdAddGET | newsedit | |
newsupdate/{userid} | newsUpdateGET | newsedit | |
newssave | newsSavePOST | json | |
newsdel | newsDelGET | json | |
newszhiding | |||
newsquxiao | |||
newsmove |
frames.jsp:id与模块无关
搜索框:id无值 就业系统 导航栏,应该加click
#sidemenu | #container-right |
#container-option |
jyxtmnu.jsp:id与模块无关
两层<li>不同的响应 无id .closeli .submenu
newsedit.jsp:大部分的id都跟模块相关
#newsedit-form #newsType #newsID #newsTitle #newsTypeID #newsTime 有问题:add时,获取了当时的系统时间;save时,又获取存储时的系统时间,怎么会不一致呢?save时不使用前台得到的时间? update时,会自动更改发布时间吗?
#linkUrl
#custom-queue 不知道做什么用
#picUrl
#custom-queue1 不知道做什么用
#newsSource
#newsAbstract
#newsContent
#news-submit
#news-cancel
newsindex.jsp:有一部分的id与模块相关
#queryform #search-title #search-typeid #search-btn #news-add #news-del #checkall
问题
新闻管理模块 完成阶段的总结
四个页面:frames.jsp, jyxt.jsp, newsindex.jsp, newsedit.jsp
js页面:common.js, form.js, uploadify.js分散,jquery.validate.js分散, 把newslist.jsp的js都放入common.js中
controller:FileUtilController, newsInfController
前后端双层验证,uploadify,ckeditor,ckfinder,newseditor重写,newslist整合进newsindex,class,id命名规范,js统一放在一起。
部署在linux上,tomcat如何配置?
接下来把js写成模块化,只给window增加一个变量。 ok
存在的问题:
http://localhost:8080/favicon.ico 还没有。
uploadify.swf会多发两次请求。 ok