我也开源啦!freemarker+struts2+Spring+Hibernate的项目,还用到了extjs,JQuery,Ajax用JSON。大家来围观,源代码在:
https://github.com/gazeldx/javaee-ssh-freemarker
我是在jeecms的架构基础上进行了一系列的封装,使得代码量少了很多。
jquery架构与freemarker整合,所有的验证都不需要特别写js,只要写vld="required:true,dateISO:true。。。。"这样就可以了。
实现一个增删改查全功能,代码如下:
先看view部分代码:
效果图:
列表 list.ftl
<@p.list_top><#include "/c/stock/search_simple.ftl"><#include "searchAdv.ftl"></@p.list_top>
<@p.table operateType=1 cols=[
{"name":"billid","label":"_mar_billid","type":"preview"}
{"name":"billdate","label":"_mar_billdate"}
{"name":"billstate","label":"_billstate"}
{"name":"operator2.name","label":"_operator"}
{"name":"checker2.name","label":"_checker"}
{"name":"memo","label":"_memo"}]
/>
<@p.extSelectGoods/>
<#include "/c/list_bottom.ftl">
列表中包含了高级检索 advSearch.ftl
<@s.set name="_billid" value="%{getText('_mar_billid')}"/>
<#include "/c/global/stock.ftl">
<@p.searchAdvHead/>
<#include "/c/stock/search_head.ftl">
<tr><td>${_goods_shortname}</td><td><@p.text name="queryGoodsName" id='queryGoodsName' value="" size="14" title="${_please_select_goods_to_active}"/><@p.hidden id="queryGdsid" name="queryGdsid"/></td>
<td colspan="2"> </td>
<@p.tr/>
<td colspan="2">${_billid}<@p.text name="queryBillid" value="${queryBillid!}" size="10" title="${_whole_word_match_ignore_others}"/></td>
<td colspan="2">${_memo}<@p.text name="queryMemo" value="${queryMemo!}" size="10"/></td></tr>
<#include "/c/stock/oper_checker.ftl">
<@p.searchAdvFoot/>
新增 add.ftl:
<#global type="add"> <#include "head.ftl"> <@p.form> <@p.add_ss/> <@p.text label="_mar_billdate" name="billdate"/> <@p.textarea label="_memo" name="bean.memo" vld="stringMaxLength:200"/> <@p.tr/> <#include "/c/s-end.ftl"> </@p.form>
效果图:
head.ftl
<#global _billid="_mar_billid">
<#global cols=[
{"name":"code","label":"_goods_code"}
{"name":"name","label":"_goods_name"}
{"name":"units","label":"_goods_havecount"}]
>
<#include "/c/s-head.ftl">
新增中有用extjs处理明细物料的 ext.ftl
预览 view.ftl
<@p.viewTop/>
<@p.viewTable>
<@p.view_ss label="_mar_billid"/>
<@p.td label="_mar_billdate" content="bean.billdate"/>
<@p.td label="_memo" content="bean.memo"/>
<@p.tr/>
</@p.viewTable>
<@p.tableExtSimple/>
<@p.extView cols=[
{"name":"code","label":"_goods_code"}
{"name":"name","label":"_goods_name"}
{"name":"units","label":"_goods_havecount"}]
/>
<#include "/c/view_bottom.ftl">
再看Action等类
package com.atech.stock.action;
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("stock.marAct")
public class MarAct extends StockCoreAction {
/**
* 查询列表
*/
public String list() {
initQuery();//..一些业务初始化工作
this.pagination = stockMng.querySimple(queryFdate, queryBillstate, DBConstants.Stock_Siotypeid_Mar, pageParams);
return LIST;
}
/**
* 高级检索
* @return
*/
public String queryAdvance() {
initQuery();
this.pagination = stockMng.queryAdvanceMar(queryFdate, queryBillstate, queryStartDate, queryEndDate, queryMemo, queryBillid, queryGdsid, queryOperatorid, queryCheckerid, pageParams);
return LIST;
}
void initQuery() {
//..一些初始化工作
}
}
你会问:保存、修改、删除的业务逻辑在哪里?答案是:全部封装好到父类了,不用写啦
struts.xml引入的xml代码
<package name="stock.mar" namespace="/admin/stock/mar" extends="core-default">
<action name="Com_*" method="{1}" class="stock.marAct">
<result name="list">/WEB-INF/stock_sys/mar/list.ftl</result>
<result name="add">/WEB-INF/stock_sys/mar/add.ftl</result>
<result name="edit">/WEB-INF/stock_sys/mar/edit.ftl</result>
<result name="view">/WEB-INF/stock_sys/mar/view.ftl</result>
</action>
</package>
剩下的就是hibernate的hbm和实体类代码了,比较简单,故略去。
再不需要其他代码了。
效果图片见附件