Smartclient+demo+实例

此文为转载

 

用实例见证smartclient的厉害吧。Smartclient+demo+实例_第1张图片

[html] view plain copy print ?
 
  1. 先貼出來圖片炫炫!很閃吧。
  2. 建表語句:
  3. createtablesupplyItem(
  4. itemIDintprimarykeyidentity(1,1),
  5. itemNamevarchar(300),
  6. unitCostdecimal(28,2),--55.23
  7. SKUvarchar(30),
  8. descriptionvarchar(5000),
  9. categoryvarchar(128),
  10. inStockvarchar(30),
  11. unitsvarchar(30),
  12. nextShipmentdatetime
  13. )
  14. --droptablesupplyCategory
  15. createtablesupplyCategory(
  16. categoryNamevarchar(128)primarykey,
  17. parentIDvarchar(255),
  18. )
  19. demoAppJS.jsp
  20. Jsp代碼:
  21. <!--------------------------------------------------------------------
  22. 整合人:舒婷*_*
  23. ---------------------------------------------------------------------->
  24. <HTML>
  25. <HEAD>
  26. <TITLE>SmartClientDemoApplication</TITLE>
  27. <metahttp-equiv="pragma"content="no-cache">
  28. <metahttp-equiv="cache-control"content="no-cache">
  29. <metahttp-equiv="expires"content="0">
  30. <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
  31. <metahttp-equiv="description"content="Thisismypage">
  32. <SCRIPT>varisomorphicDir="isomorphic/";</SCRIPT>
  33. <SCRIPTSRC=smartclient/modules/ISC_History.js></SCRIPT>
  34. <SCRIPTSRC=smartclient/modules/ISC_Core.js></SCRIPT>
  35. <SCRIPTSRC=smartclient/modules/ISC_Foundation.js></SCRIPT>
  36. <SCRIPTSRC=smartclient/modules/ISC_Containers.js></SCRIPT>
  37. <SCRIPTSRC=smartclient/modules/ISC_Grids.js></SCRIPT>
  38. <SCRIPTSRC=smartclient/modules/ISC_Forms.js></SCRIPT>
  39. <SCRIPTSRC=smartclient/modules/ISC_DataBinding.js></SCRIPT>
  40. <SCRIPTSRC=smartclient/modules/load_skin.js></SCRIPT>
  41. </HEAD>
  42. <BODYCLASS="pageBackground"STYLE="overflow:hidden">
  43. <scriptsrc="demoAppJS.js"></script>
  44. </BODY>
  45. </HTML>
  46. demoAppJS.js
  47. isc.setAutoDraw(false);
  48. //<isomorphic:loadDSname="supplyItem"/>
  49. //<isomorphic:loadDSname="supplyCategory"/>
  50. isc.DataSource.create({
  51. ID:"supplyCategory",
  52. dataFormat:"xml",
  53. recordXPath:"//country",
  54. fields:[
  55. {name:"categoryName",primaryKey:true},
  56. {foreignKey:"supplyCategory.categoryName",//这一步不懂、??
  57. hidden:true,
  58. name:"parentID",
  59. required:true,
  60. rootValue:"root",//初始化加载parentID为root记录如果没有设置rootValue会出现死循环式的树
  61. type:"text"
  62. }
  63. ],
  64. operationBindings:[
  65. {
  66. operationType:"fetch",
  67. dataURL:"demoApp/findTreeAll.action"
  68. }
  69. ]
  70. });
  71. isc.DataSource.create({
  72. ID:"supplyItem",
  73. dataFormat:"xml",//数据格式xml格式
  74. recordXPath:"//country",//--<country></country>
  75. fields:[
  76. //{name:"itemId",primaryKey:true},//countryCode設置為主鍵
  77. {name:"itemName",title:"itemName"},
  78. {name:"unitCost",title:"unitCost"},
  79. {name:"SKU",title:"SKU"},
  80. {name:"description",title:"description"},
  81. {name:"category",title:"category"},
  82. {name:"inStock",title:"inStock"},
  83. {name:"nextShipment",title:"nextShipment"}
  84. ],
  85. operationBindings:[
  86. {operationType:"fetch",
  87. dataURL:"demoApp/findAll.action"
  88. },
  89. {operationType:"add"
  90. //dataURL:"country/insertInfo.action"
  91. },
  92. {operationType:"update"
  93. //dataURL:"country/updateInfo.action"
  94. },
  95. {operationType:"remove"
  96. //dataURL:"country/deleteInfo.action"
  97. }
  98. ]
  99. });
  100. isc.Page.setAppImgDir(isc.Page.getIsomorphicDocsDir()+"exampleImages/");//设置img文件路径
  101. isc.TreeGrid.create({
  102. ID:"categoryTree",
  103. dataSource:"supplyCategory",
  104. nodeClick:"findForm.findItems(node.categoryName)",
  105. showHeader:false,
  106. leaveScrollbarGap:false,
  107. animateFolders:true,
  108. canAcceptDroppedRecords:true,
  109. canReparentNodes:false,
  110. selectionType:"single",
  111. animateRowsMaxTime:750
  112. });
  113. isc.HTMLPane.create({
  114. ID:"helpCanvas",
  115. contentsURL:"demoApp_helpText.html",
  116. overflow:"auto",
  117. styleName:"defaultBorder",
  118. padding:10
  119. });
  120. isc.IButton.create({
  121. ID:"findButton",
  122. title:"Find",
  123. left:25,
  124. top:16,
  125. width:80,
  126. click:"findForm.findItems()",
  127. icon:"demoApp/icon_find.png",
  128. iconWidth:24
  129. });
  130. isc.SearchForm.create({
  131. ID:"findForm",
  132. dataSource:supplyItem,
  133. left:130,
  134. top:10,
  135. cellPadding:4,
  136. numCols:6,
  137. fields:[
  138. {name:"SKU"},
  139. {name:"itemName",editorType:"comboBox",optionDataSource:"supplyItem",
  140. pickListWidth:250},
  141. {name:"findInCategory",editorType:"checkbox",
  142. title:"Usecategory",defaultValue:true,shouldSaveValue:false}
  143. ],
  144. //Functiontoactuallyfinditems
  145. findItems:function(categoryName){
  146. varfindValues;
  147. if(this.getValue('findInCategory')&&categoryTree.selection.anySelected()){
  148. //usetreecategoryandformvalues
  149. if(categoryName==null)categoryName=categoryTree.getSelectedRecord().categoryName;
  150. findValues={category:categoryName};
  151. isc.addProperties(findValues,this.getValues());
  152. }elseif(categoryName==null){
  153. //useformvaluesonly
  154. findValues=this.getValues();
  155. }else{
  156. //usetreecategoryonly
  157. findValues={category:categoryName};
  158. }
  159. itemList.filterData(findValues);
  160. itemDetailTabs.clearDetails();
  161. }
  162. });
  163. isc.ListGrid.create({
  164. ID:"itemList",
  165. dataSource:supplyItem,
  166. useAllDataSourceFields:true,
  167. fields:[
  168. {name:"itemName",title:"Name",showHover:true},
  169. {name:"unitCost",
  170. formatCellValue:"returnisc.Format.toCurrencyString(parseFloat(value))",
  171. editorType:"spinner",editorProperties:{step:0.01}},
  172. {name:"SKU",canEdit:false},
  173. {name:"description",showHover:true},
  174. {name:"category",canEdit:false},
  175. {name:"inStock",width:55,align:"center",
  176. formatCellValue:function(value,record,field,rowNum,colNum){
  177. if(value)returnisc.Canvas.imgHTML("demoApp/checked.png",13,13);
  178. elsereturnisc.Canvas.imgHTML("demoApp/unchecked.png",13,13)
  179. }},
  180. {name:"nextShipment",showIf:"false"}
  181. ],
  182. recordClick:"this.updateDetails()",
  183. canEdit:true,
  184. modalEditing:true,
  185. cellChanged:"this.updateDetails()",
  186. alternateRecordStyles:true,
  187. canDragRecordsOut:true,
  188. hoverWidth:200,
  189. hoverHeight:20,
  190. selectionType:"single",
  191. cellContextClick:"returnitemListMenu.showContextMenu()",
  192. updateDetails:function(){
  193. varrecord=this.getSelectedRecord();
  194. if(record==null)returnitemDetailTabs.clearDetails();
  195. if(itemDetailTabs.getSelectedTabNumber()==0){itemViewer.setData(record)
  196. }else{
  197. itemDetailTabs.updateTab("editTab",editForm);
  198. editForm.editRecord(record);
  199. }
  200. }
  201. });
  202. isc.Menu.create({
  203. ID:"itemListMenu",
  204. cellHeight:22,
  205. data:[
  206. {title:"AddNewItem",
  207. icon:"demoApp/icon_add.png",
  208. click:function(){
  209. itemList.selection.deselectAll();
  210. itemDetailTabs.selectTab(1);
  211. itemList.updateDetails();
  212. }
  213. },
  214. {isSeparator:true},
  215. {title:"ShowDetails",
  216. icon:"demoApp/icon_view.png",
  217. click:"itemDetailTabs.selectTab(0);itemList.updateDetails()"},
  218. {title:"EditItem",
  219. icon:"demoApp/icon_edit.png",
  220. click:"itemDetailTabs.selectTab(1);itemList.updateDetails()"},
  221. {title:"DeleteItem",
  222. icon:"demoApp/icon_delete.png",
  223. click:"itemList.removeSelectedData();itemDetailTabs.clearDetails()"}
  224. ]
  225. });
  226. isc.DetailViewer.create({
  227. ID:"itemViewer",
  228. dataSource:supplyItem,
  229. width:"100%",
  230. margin:"25",
  231. emptyMessage:"Selectanitemtoviewitsdetails"
  232. });
  233. isc.DynamicForm.create({
  234. ID:"editForm",
  235. dataSource:supplyItem,
  236. useAllDataSourceFields:true,
  237. fields:[
  238. {name:"SKU"},
  239. {name:"description",editorType:"textArea",rowSpan:3,width:200},
  240. {name:"category",editorType:"pickTree",dataSource:supplyCategory,//无法显示editform
  241. emptyMenuMessage:"NoSubCategories",canSelectParentItems:true},
  242. {name:"unitCost",editorType:"spinner",step:0.01},
  243. {name:"inStock"},
  244. {name:"nextShipment",useTextField:true,editorType:"date"},
  245. {name:"savebtn",editorType:"button",align:"center",
  246. width:100,colSpan:4,title:"SaveItem",click:"editForm.saveData()"}
  247. ],
  248. width:650,
  249. numCols:4,
  250. colWidths:[100,200,100,200],
  251. margin:25,
  252. cellPadding:5,
  253. autoFocus:false
  254. });
  255. isc.Label.create({
  256. ID:"editorMessage",
  257. autoDraw:false,
  258. width:"100%",
  259. height:"100%",
  260. align:"center",
  261. contents:"Selectarecordtoedit,oracategorytoinsertanewrecordinto"
  262. });
  263. isc.TabSet.create({
  264. ID:"itemDetailTabs",
  265. tabs:[
  266. {title:"View",pane:itemViewer,ID:"viewTab",width:70,icon:"demoApp/icon_view.png"},
  267. {title:"Edit",pane:editForm,ID:"editTab",width:70,icon:"demoApp/icon_edit.png"}
  268. ],
  269. tabSelected:"itemList.updateDetails()",
  270. clearDetails:function(){
  271. varselectedTab=this.getSelectedTabNumber();
  272. if(selectedTab==0){
  273. itemViewer.setData();
  274. }elseif(selectedTab==1){
  275. if(categoryTree.getSelectedRecord()!=null){
  276. this.updateTab("editTab",editForm);
  277. editForm.editNewRecord({category:categoryTree.getSelectedRecord().categoryName});
  278. }else{
  279. this.updateTab("editTab",editorMessage);
  280. }
  281. }
  282. }
  283. });
  284. //Defineapplicationlayout
  285. //---------------------------------------------------------------------
  286. isc.HLayout.create({
  287. ID:"pageLayout",
  288. width:"100%",
  289. height:"100%",
  290. layoutMargin:20,
  291. members:[
  292. isc.SectionStack.create({
  293. ID:"leftSideLayout",
  294. width:280,
  295. showResizeBar:true,
  296. visibilityMode:"multiple",
  297. animateSections:true,
  298. sections:[
  299. {title:"OfficeSupplyCategories",autoShow:true,items:[categoryTree]},
  300. {title:"Instructions",autoShow:true,items:[helpCanvas]}
  301. ]
  302. }),
  303. isc.SectionStack.create({
  304. ID:"rightSideLayout",
  305. visibilityMode:"multiple",
  306. animateSections:true,
  307. sections:[
  308. {title:"FindItems",autoShow:true,items:[
  309. isc.Canvas.create({
  310. ID:"findPane",
  311. height:60,
  312. overflow:"auto",
  313. styleName:"defaultBorder",
  314. children:[findForm,findButton]
  315. })
  316. ]},
  317. {title:"OfficeSupplyItems",autoShow:true,items:[itemList]},
  318. {title:"ItemDetails",autoShow:true,items:[itemDetailTabs]}
  319. ]
  320. })
  321. ]
  322. });
  323. isc.Page.setEvent("load","pageLayout.draw()");
  324. //Customlogic:
  325. //Whenshowingoptionsinthecombo-box,onlyshowtheoptionsfromtheselectedcategory
  326. //ifappropriate
  327. findForm.getItem("itemName").addProperties({
  328. getPickListFilterCriteria:function(){
  329. varcriteria=this.Super("getPickListFilterCriteria",arguments);
  330. if(this.form.getValue('findInCategory')&&categoryTree.selection.anySelected()){
  331. criteria.category=categoryTree.getSelectedRecord().categoryName;
  332. }
  333. returncriteria
  334. }
  335. });
  336. categoryTree.fetchData();
  337. java代碼
  338. DAO層
  339. packageisc.java.Dao;
  340. importisc.java.Module.supplyItem;
  341. importjava.util.List;
  342. importorg.hibernate.SessionFactory;
  343. importorg.springframework.beans.factory.annotation.Autowired;
  344. importorg.springframework.orm.hibernate3.HibernateTemplate;
  345. importorg.springframework.stereotype.Repository;
  346. @Repository
  347. publicclasssupplyItem_Dao{
  348. privateHibernateTemplatehibernateTemplate;
  349. @SuppressWarnings("unused")
  350. @Autowired
  351. privatevoidsetHibernateTemplate(SessionFactorysessionFactory){
  352. this.hibernateTemplate=newHibernateTemplate(sessionFactory);
  353. }
  354. /*
  355. *functionfindAll
  356. *查询supplyItem表中所有记录
  357. *并以list形式返回
  358. *
  359. **/
  360. @SuppressWarnings("unchecked")
  361. publicList<supplyItem>findAll(Stringcategory){
  362. Stringhql="fromsupplyItemwherecategory='"+category+"'";
  363. Listlist=this.hibernateTemplate.find(hql);
  364. returnlist;
  365. }
  366. /*
  367. *根据category返回对应的记录
  368. **/
  369. @SuppressWarnings("unchecked")
  370. publicsupplyItemfindInfoByID(intitemID){
  371. supplyItemsupp=(supplyItem)this.hibernateTemplate.get(supplyItem.class,itemID);
  372. returnsupp;
  373. }
  374. /*
  375. *删除指定记录
  376. *
  377. **/
  378. publicvoiddeleteInfo(supplyItemsupp){
  379. this.hibernateTemplate.delete(supp);
  380. }
  381. /*
  382. *更新修改后的记录
  383. **/
  384. publicvoidupdateInfo(supplyItemsupp){
  385. this.hibernateTemplate.update(supp);
  386. }
  387. /*
  388. *增加记录
  389. **/
  390. publicvoidinsertInfo(supplyItemsupp){
  391. this.hibernateTemplate.save(supp);
  392. }
  393. }
  394. packageisc.java.Dao;
  395. importisc.java.Module.supplyCategory;
  396. importjava.util.List;
  397. importorg.hibernate.SessionFactory;
  398. importorg.springframework.beans.factory.annotation.Autowired;
  399. importorg.springframework.orm.hibernate3.HibernateTemplate;
  400. importorg.springframework.stereotype.Repository;
  401. @Repository
  402. publicclasssupplyCategory_Dao{
  403. privateHibernateTemplatehibernateTemplate;
  404. @SuppressWarnings("unused")
  405. @Autowired
  406. privatevoidsetHibernateTemplate(SessionFactorysessionFactory){
  407. this.hibernateTemplate=newHibernateTemplate(sessionFactory);
  408. }
  409. @SuppressWarnings("unchecked")
  410. publicList<supplyCategory>findAll(StringparentId){
  411. Stringhql="fromsupplyCategorywhereparentId='"+parentId+"'";
  412. Listlist=this.hibernateTemplate.find(hql);
  413. returnlist;
  414. }
  415. }
  416. ENTITY層
  417. packageisc.java.Module;
  418. importjavax.persistence.Column;
  419. importjavax.persistence.Entity;
  420. importjavax.persistence.Id;
  421. importjavax.persistence.Table;
  422. @Entity
  423. @Table(name="supplyCategory")
  424. publicclasssupplyCategory{
  425. privateStringcategoryName;
  426. privateStringparentId;
  427. @Id
  428. @Column(name="categoryName")
  429. publicStringgetCategoryName(){
  430. returncategoryName;
  431. }
  432. publicvoidsetCategoryName(StringcategoryName){
  433. this.categoryName=categoryName;
  434. }
  435. @Column(name="parentId")
  436. publicStringgetParentId(){
  437. returnparentId;
  438. }
  439. publicvoidsetParentId(StringparentId){
  440. this.parentId=parentId;
  441. }
  442. }
  443. packageisc.java.Module;
  444. importjavax.persistence.Column;
  445. importjavax.persistence.Entity;
  446. importjavax.persistence.GeneratedValue;
  447. importjavax.persistence.Id;
  448. importjavax.persistence.Table;
  449. @Entity
  450. @Table(name="supplyItem")
  451. publicclasssupplyItem{
  452. privateintitemID;
  453. privateStringitemName;
  454. privatedoubleunitCost;
  455. privateStringSKU;
  456. privateStringdescription;
  457. privateStringcategory;
  458. privateStringinStock;
  459. privateStringnextShipment;
  460. @Id
  461. @GeneratedValue
  462. @Column(name="itemID")
  463. publicintgetItemID(){
  464. returnitemID;
  465. }
  466. publicvoidsetItemID(intitemID){
  467. this.itemID=itemID;
  468. }
  469. @Column(name="itemName")
  470. publicStringgetItemName(){
  471. returnitemName;
  472. }
  473. publicvoidsetItemName(StringitemName){
  474. this.itemName=itemName;
  475. }
  476. @Column(name="unitCost")
  477. publicdoublegetUnitCost(){
  478. returnunitCost;
  479. }
  480. publicvoidsetUnitCost(doubleunitCost){
  481. this.unitCost=unitCost;
  482. }
  483. @Column(name="SKU")
  484. publicStringgetSKU(){
  485. returnSKU;
  486. }
  487. publicvoidsetSKU(Stringsku){
  488. SKU=sku;
  489. }
  490. @Column(name="description")
  491. publicStringgetDescription(){
  492. returndescription;
  493. }
  494. publicvoidsetDescription(Stringdescription){
  495. this.description=description;
  496. }
  497. @Column(name="category")
  498. publicStringgetCategory(){
  499. returncategory;
  500. }
  501. publicvoidsetCategory(Stringcategory){
  502. this.category=category;
  503. }
  504. @Column(name="instock")
  505. publicStringgetInStock(){
  506. returninStock;
  507. }
  508. publicvoidsetInStock(StringinStock){
  509. this.inStock=inStock;
  510. }
  511. @Column(name="nextShipment")
  512. publicStringgetNextShipment(){
  513. returnnextShipment;
  514. }
  515. publicvoidsetNextShipment(StringnextShipment){
  516. this.nextShipment=nextShipment;
  517. }
  518. }
  519. Service層
  520. packageisc.java.Service;
  521. importisc.java.Dao.supplyCategory_Dao;
  522. importisc.java.Module.supplyCategory;
  523. importjava.util.List;
  524. importorg.springframework.beans.factory.annotation.Autowired;
  525. importorg.springframework.stereotype.Service;
  526. importorg.springframework.transaction.annotation.Transactional;
  527. @Service
  528. publicclasssupplyCategory_Service{
  529. privatesupplyCategory_DaosupplyCategory_dao;
  530. @Autowired
  531. publicvoidsetSupplyCategory_dao(supplyCategory_DaosupplyCategory_dao){
  532. this.supplyCategory_dao=supplyCategory_dao;
  533. }
  534. @Transactional("demoApp")
  535. publicList<supplyCategory>findAll(StringparentId){
  536. returnthis.supplyCategory_dao.findAll(parentId);
  537. }
  538. }
  539. packageisc.java.Service;
  540. importisc.java.Dao.supplyItem_Dao;
  541. importisc.java.Module.supplyItem;
  542. importjava.util.List;
  543. importorg.springframework.beans.factory.annotation.Autowired;
  544. importorg.springframework.stereotype.Service;
  545. importorg.springframework.transaction.annotation.Transactional;
  546. @Service
  547. publicclasssupplyItem_Service{
  548. privatesupplyItem_DaosupplyItem_dao;
  549. @Autowired
  550. publicvoidsetSupplyItem_dao(supplyItem_DaosupplyItem_dao){
  551. this.supplyItem_dao=supplyItem_dao;
  552. }
  553. /*
  554. *使用声明式事物管理
  555. *在业务方法上进行@Transactional注解
  556. *将事物规则应用到业务逻辑中
  557. *demoApp为限定词*_*
  558. **/
  559. @Transactional("demoApp")
  560. publicList<supplyItem>findAll(Stringcategory){
  561. returnthis.supplyItem_dao.findAll(category);
  562. }
  563. @Transactional("demoApp")
  564. publicsupplyItemfindInfoByID(intitemID){
  565. returnthis.supplyItem_dao.findInfoByID(itemID);
  566. }
  567. @Transactional("demoApp")
  568. publicvoiddeleteInfo(intitemID){
  569. supplyItemsupp=this.supplyItem_dao.findInfoByID(itemID);
  570. this.supplyItem_dao.deleteInfo(supp);
  571. }
  572. @Transactional("demoApp")
  573. publicvoidupdateInfo(supplyItemsupp){
  574. this.supplyItem_dao.updateInfo(supp);
  575. }
  576. @Transactional("demoApp")
  577. publicvoidinsertInfo(supplyItemsupp){
  578. this.supplyItem_dao.insertInfo(supp);
  579. }
  580. }
  581. Web層
  582. packageisc.java.Web;
  583. importisc.java.Module.supplyCategory;
  584. importisc.java.Service.supplyCategory_Service;
  585. importjava.io.IOException;
  586. importjava.util.Enumeration;
  587. importjava.util.Iterator;
  588. importjava.util.List;
  589. importjavax.servlet.ServletOutputStream;
  590. importjavax.servlet.http.HttpServletRequest;
  591. importjavax.servlet.http.HttpServletResponse;
  592. importorg.springframework.beans.factory.annotation.Autowired;
  593. importorg.springframework.stereotype.Controller;
  594. importorg.springframework.web.bind.annotation.RequestMapping;
  595. @Controller
  596. publicclasssupplyCategory_Controller{
  597. privatesupplyCategory_ServicesupplyCategory_service;
  598. @Autowired
  599. publicvoidsetSupplyCategory_service(
  600. supplyCategory_ServicesupplyCategory_service){
  601. this.supplyCategory_service=supplyCategory_service;
  602. }
  603. @SuppressWarnings("unchecked")
  604. @RequestMapping(value="demoApp/findTreeAll.action")
  605. publicvoidfindAll(HttpServletResponseresponse,HttpServletRequestrequest){
  606. StringparentId=request.getParameter("parentID");
  607. List<supplyCategory>list=this.supplyCategory_service.findAll(parentId);
  608. ServletOutputStreamsos=null;
  609. try{
  610. sos=response.getOutputStream();
  611. }catch(IOExceptione){
  612. //TODOAuto-generatedcatchblock
  613. e.printStackTrace();
  614. }
  615. StringBuffersbu=newStringBuffer();
  616. Iteratorita=(Iterator)list.iterator();
  617. while(ita.hasNext()){
  618. supplyCategorysupplycategory=(supplyCategory)ita.next();
  619. sbu.append("<country>");
  620. sbu.append("<categoryName>"+supplycategory.getCategoryName()+"</categoryName>");
  621. sbu.append("<parentId>"+supplycategory.getParentId()+"</parentId>");
  622. sbu.append("</country>");
  623. }
  624. try{
  625. sos.print("<?xmlversion='1.0'encoding='UTF-8'?><records>"+sbu.toString()+"</records>");
  626. }catch(IOExceptione){
  627. //TODOAuto-generatedcatchblock
  628. e.printStackTrace();
  629. }
  630. }
  631. }
  632. packageisc.java.Web;
  633. importisc.java.Module.supplyItem;
  634. importisc.java.Service.supplyItem_Service;
  635. importjava.io.IOException;
  636. importjava.util.Iterator;
  637. importjava.util.List;
  638. importjavax.servlet.ServletOutputStream;
  639. importjavax.servlet.http.HttpServletRequest;
  640. importjavax.servlet.http.HttpServletResponse;
  641. importorg.springframework.beans.factory.annotation.Autowired;
  642. importorg.springframework.stereotype.Controller;
  643. importorg.springframework.web.bind.annotation.RequestMapping;
  644. @Controller
  645. publicclasssupplyItem_Controller{
  646. privatesupplyItem_ServicesupplyItem_service;
  647. @Autowired
  648. publicvoidsetSupplyItem_service(supplyItem_ServicesupplyItem_service){
  649. this.supplyItem_service=supplyItem_service;
  650. }
  651. /*
  652. *从数据库中提取数据以xml格式存储
  653. *
  654. **/
  655. @SuppressWarnings("unchecked")
  656. @RequestMapping(value="demoApp/findAll.action")
  657. publicvoidfindAll(HttpServletResponseresponse,HttpServletRequestrequest){
  658. Stringcategory=request.getParameter("category");//接受前台传过来的参数
  659. List<supplyItem>list=this.supplyItem_service.findAll(category);
  660. ServletOutputStreamsos=null;
  661. try{
  662. sos=response.getOutputStream();
  663. }catch(IOExceptione){
  664. e.printStackTrace();
  665. }
  666. StringBuffersbu=newStringBuffer();
  667. Iteratorita=(Iterator)list.iterator();
  668. while(ita.hasNext()){
  669. supplyItemsupplyitem=(supplyItem)ita.next();
  670. sbu.append("<country>");
  671. sbu.append("<itemID>"+supplyitem.getItemID()+"</itemID>");
  672. sbu.append("<itemName>"+supplyitem.getItemName()+"</itemName>");
  673. sbu.append("<unitCost>"+supplyitem.getUnitCost()+"</unitCost>");
  674. sbu.append("<SKU>"+supplyitem.getSKU()+"</SKU>");
  675. sbu.append("<description>"+supplyitem.getDescription()+"</description>");
  676. sbu.append("<category>"+supplyitem.getCategory()+"</category>");
  677. sbu.append("<inStock>"+supplyitem.getInStock()+"</inStock>");
  678. sbu.append("<nextShipment>"+supplyitem.getNextShipment()+"</nextShipment>");
  679. sbu.append("</country>");
  680. }
  681. try{
  682. sos.print("<?xmlversion='1.0'encoding='UTF-8'?><records>"+sbu.toString()+"</records>");
  683. }catch(IOExceptione){
  684. e.printStackTrace();
  685. }
  686. }
  687. @RequestMapping(value="demoApp/deleteInfo.action")
  688. publicvoiddeleteInfo(HttpServletRequestrequest){
  689. intitemID=Integer.parseInt(request.getParameter("itemID"));
  690. System.out.println("test======================"+itemID);
  691. this.supplyItem_service.deleteInfo(itemID);
  692. }
  693. @RequestMapping(value="demoApp/updateInfo.action")
  694. publicvoidupdateInfo(HttpServletRequestrequest){
  695. intitemID=Integer.parseInt(request.getParameter("itemID"));
  696. supplyItemsupp=this.supplyItem_service.findInfoByID(itemID);
  697. supp.setSKU(request.getParameter("SKU"));
  698. supp.setCategory(request.getParameter("category"));
  699. supp.setDescription(request.getParameter("description"));
  700. supp.setInStock(request.getParameter("inStock"));
  701. supp.setItemName(request.getParameter("itemName"));
  702. supp.setNextShipment(request.getParameter("nextShipment"));
  703. Strings=request.getParameter("unitCost");
  704. supp.setUnitCost(Double.parseDouble(s));
  705. this.supplyItem_service.updateInfo(supp);
  706. }
  707. @RequestMapping(value="demoApp/insertInfo.action")
  708. publicvoidinsertInfo(HttpServletRequestrequest){
  709. supplyItemsupp=newsupplyItem();
  710. supp.setCategory(request.getParameter("category"));
  711. supp.setSKU(request.getParameter("SKU"));
  712. supp.setDescription(request.getParameter("description"));
  713. supp.setInStock(request.getParameter("inStock"));
  714. supp.setItemName(request.getParameter("itemName"));
  715. supp.setNextShipment(request.getParameter("nextShipment"));
  716. supp.setUnitCost(Double.parseDouble(request.getParameter("unitCost")));
  717. this.supplyItem_service.insertInfo(supp);
  718. }
  719. }
  720. Xml
  721. App-config.xml
  722. <?xmlversion="1.0"encoding="UTF-8"?>
  723. <beansxmlns="http://www.springframework.org/schema/beans"
  724. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  725. xmlns:mvc="http://www.springframework.org/schema/mvc"
  726. xmlns:context="http://www.springframework.org/schema/context"
  727. xsi:schemaLocation="
  728. http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  729. http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd
  730. http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
  731. <!--Scanstheclasspathofthisapplicationfor@Componentstodeployasbeans-->
  732. <!--規約所有進行掃描的類,以完成Bean創建和自動依賴注入功能-->
  733. <context:component-scanbase-package="isc.java.*"/>
  734. <!--<context:annotation-config/>-->
  735. <!--Configuresthe@Controllerprogrammingmodel-->
  736. <mvc:annotation-driven/>
  737. <!--misc-->
  738. <beanid="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  739. <propertyname="viewClass"value="org.springframework.web.servlet.view.JstlView"/>
  740. <propertyname="suffix"value=".action"/>
  741. </bean>
  742. <!--ConfiguresHibernate-DatabaseConfig-->
  743. <importresource="db-config.xml"/>
  744. </beans>
  745. Db-config.xml
  746. <?xmlversion="1.0"encoding="UTF-8"?>
  747. <beansxmlns="http://www.springframework.org/schema/beans"
  748. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  749. xmlns:tx="http://www.springframework.org/schema/tx"
  750. xmlns:aop="http://www.springframework.org/schema/aop"
  751. xsi:schemaLocation="
  752. http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  753. http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  754. http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
  755. <beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  756. <propertyname="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>
  757. <propertyname="url"><value>jdbc:sqlserver://10.1.100.215:1433;DatabaseName=email</value></property>
  758. <propertyname="username"><value>dev</value></property>
  759. <propertyname="password"><value>12345678aA</value></property>
  760. </bean>
  761. <beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  762. <propertyname="dataSource"><reflocal="dataSource"/></property>
  763. <propertyname="packagesToScan"value="isc.java.*"/>
  764. <propertyname="hibernateProperties">
  765. <props>
  766. <propkey="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
  767. <propkey="hibernate.show_sql">true</prop>
  768. <!--<propkey="hibernate.hbm2ddl.auto">update</prop>-->
  769. <propkey="hibernate.format_sql">true</prop>
  770. </props>
  771. </property>
  772. </bean>
  773. <!--TransactionmanagerforasingleHibernateSessionFactory(alternativetoJTA)-->
  774. <tx:annotation-driven/>
  775. <beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  776. <propertyname="sessionFactory"><reflocal="sessionFactory"/></property>
  777. <qualifiervalue="demoApp"/><!--限定词-->
  778. </bean>
  779. </beans>

 

你可能感兴趣的:(demo,smartcleint)