此文为转载
- 先貼出來圖片炫炫!很閃吧。
- 建表語句:
- createtablesupplyItem(
- itemIDintprimarykeyidentity(1,1),
- itemNamevarchar(300),
- unitCostdecimal(28,2),--55.23
- SKUvarchar(30),
- descriptionvarchar(5000),
- categoryvarchar(128),
- inStockvarchar(30),
- unitsvarchar(30),
- nextShipmentdatetime
- )
- --droptablesupplyCategory
- createtablesupplyCategory(
- categoryNamevarchar(128)primarykey,
- parentIDvarchar(255),
- )
- demoAppJS.jsp
- Jsp代碼:
- <!--------------------------------------------------------------------
- 整合人:舒婷*_*
- ---------------------------------------------------------------------->
- <HTML>
- <HEAD>
- <TITLE>SmartClientDemoApplication</TITLE>
- <metahttp-equiv="pragma"content="no-cache">
- <metahttp-equiv="cache-control"content="no-cache">
- <metahttp-equiv="expires"content="0">
- <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equiv="description"content="Thisismypage">
- <SCRIPT>varisomorphicDir="isomorphic/";</SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_History.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_Core.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_Foundation.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_Containers.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_Grids.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_Forms.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/ISC_DataBinding.js></SCRIPT>
- <SCRIPTSRC=smartclient/modules/load_skin.js></SCRIPT>
- </HEAD>
- <BODYCLASS="pageBackground"STYLE="overflow:hidden">
- <scriptsrc="demoAppJS.js"></script>
- </BODY>
- </HTML>
- demoAppJS.js
- isc.setAutoDraw(false);
- //<isomorphic:loadDSname="supplyItem"/>
- //<isomorphic:loadDSname="supplyCategory"/>
- isc.DataSource.create({
- ID:"supplyCategory",
- dataFormat:"xml",
- recordXPath:"//country",
- fields:[
- {name:"categoryName",primaryKey:true},
- {foreignKey:"supplyCategory.categoryName",//这一步不懂、??
- hidden:true,
- name:"parentID",
- required:true,
- rootValue:"root",//初始化加载parentID为root记录如果没有设置rootValue会出现死循环式的树
- type:"text"
- }
- ],
- operationBindings:[
- {
- operationType:"fetch",
- dataURL:"demoApp/findTreeAll.action"
- }
- ]
- });
- isc.DataSource.create({
- ID:"supplyItem",
- dataFormat:"xml",//数据格式xml格式
- recordXPath:"//country",//--<country></country>
- fields:[
- //{name:"itemId",primaryKey:true},//countryCode設置為主鍵
- {name:"itemName",title:"itemName"},
- {name:"unitCost",title:"unitCost"},
- {name:"SKU",title:"SKU"},
- {name:"description",title:"description"},
- {name:"category",title:"category"},
- {name:"inStock",title:"inStock"},
- {name:"nextShipment",title:"nextShipment"}
- ],
- operationBindings:[
- {operationType:"fetch",
- dataURL:"demoApp/findAll.action"
- },
- {operationType:"add"
- //dataURL:"country/insertInfo.action"
- },
- {operationType:"update"
- //dataURL:"country/updateInfo.action"
- },
- {operationType:"remove"
- //dataURL:"country/deleteInfo.action"
- }
- ]
- });
- isc.Page.setAppImgDir(isc.Page.getIsomorphicDocsDir()+"exampleImages/");//设置img文件路径
- isc.TreeGrid.create({
- ID:"categoryTree",
- dataSource:"supplyCategory",
- nodeClick:"findForm.findItems(node.categoryName)",
- showHeader:false,
- leaveScrollbarGap:false,
- animateFolders:true,
- canAcceptDroppedRecords:true,
- canReparentNodes:false,
- selectionType:"single",
- animateRowsMaxTime:750
- });
- isc.HTMLPane.create({
- ID:"helpCanvas",
- contentsURL:"demoApp_helpText.html",
- overflow:"auto",
- styleName:"defaultBorder",
- padding:10
- });
- isc.IButton.create({
- ID:"findButton",
- title:"Find",
- left:25,
- top:16,
- width:80,
- click:"findForm.findItems()",
- icon:"demoApp/icon_find.png",
- iconWidth:24
- });
- isc.SearchForm.create({
- ID:"findForm",
- dataSource:supplyItem,
- left:130,
- top:10,
- cellPadding:4,
- numCols:6,
- fields:[
- {name:"SKU"},
- {name:"itemName",editorType:"comboBox",optionDataSource:"supplyItem",
- pickListWidth:250},
- {name:"findInCategory",editorType:"checkbox",
- title:"Usecategory",defaultValue:true,shouldSaveValue:false}
- ],
- //Functiontoactuallyfinditems
- findItems:function(categoryName){
- varfindValues;
- if(this.getValue('findInCategory')&&categoryTree.selection.anySelected()){
- //usetreecategoryandformvalues
- if(categoryName==null)categoryName=categoryTree.getSelectedRecord().categoryName;
- findValues={category:categoryName};
- isc.addProperties(findValues,this.getValues());
- }elseif(categoryName==null){
- //useformvaluesonly
- findValues=this.getValues();
- }else{
- //usetreecategoryonly
- findValues={category:categoryName};
- }
- itemList.filterData(findValues);
- itemDetailTabs.clearDetails();
- }
- });
- isc.ListGrid.create({
- ID:"itemList",
- dataSource:supplyItem,
- useAllDataSourceFields:true,
- fields:[
- {name:"itemName",title:"Name",showHover:true},
- {name:"unitCost",
- formatCellValue:"returnisc.Format.toCurrencyString(parseFloat(value))",
- editorType:"spinner",editorProperties:{step:0.01}},
- {name:"SKU",canEdit:false},
- {name:"description",showHover:true},
- {name:"category",canEdit:false},
- {name:"inStock",width:55,align:"center",
- formatCellValue:function(value,record,field,rowNum,colNum){
- if(value)returnisc.Canvas.imgHTML("demoApp/checked.png",13,13);
- elsereturnisc.Canvas.imgHTML("demoApp/unchecked.png",13,13)
- }},
- {name:"nextShipment",showIf:"false"}
- ],
- recordClick:"this.updateDetails()",
- canEdit:true,
- modalEditing:true,
- cellChanged:"this.updateDetails()",
- alternateRecordStyles:true,
- canDragRecordsOut:true,
- hoverWidth:200,
- hoverHeight:20,
- selectionType:"single",
- cellContextClick:"returnitemListMenu.showContextMenu()",
- updateDetails:function(){
- varrecord=this.getSelectedRecord();
- if(record==null)returnitemDetailTabs.clearDetails();
- if(itemDetailTabs.getSelectedTabNumber()==0){itemViewer.setData(record)
- }else{
- itemDetailTabs.updateTab("editTab",editForm);
- editForm.editRecord(record);
- }
- }
- });
- isc.Menu.create({
- ID:"itemListMenu",
- cellHeight:22,
- data:[
- {title:"AddNewItem",
- icon:"demoApp/icon_add.png",
- click:function(){
- itemList.selection.deselectAll();
- itemDetailTabs.selectTab(1);
- itemList.updateDetails();
- }
- },
- {isSeparator:true},
- {title:"ShowDetails",
- icon:"demoApp/icon_view.png",
- click:"itemDetailTabs.selectTab(0);itemList.updateDetails()"},
- {title:"EditItem",
- icon:"demoApp/icon_edit.png",
- click:"itemDetailTabs.selectTab(1);itemList.updateDetails()"},
- {title:"DeleteItem",
- icon:"demoApp/icon_delete.png",
- click:"itemList.removeSelectedData();itemDetailTabs.clearDetails()"}
- ]
- });
- isc.DetailViewer.create({
- ID:"itemViewer",
- dataSource:supplyItem,
- width:"100%",
- margin:"25",
- emptyMessage:"Selectanitemtoviewitsdetails"
- });
- isc.DynamicForm.create({
- ID:"editForm",
- dataSource:supplyItem,
- useAllDataSourceFields:true,
- fields:[
- {name:"SKU"},
- {name:"description",editorType:"textArea",rowSpan:3,width:200},
- {name:"category",editorType:"pickTree",dataSource:supplyCategory,//无法显示editform
- emptyMenuMessage:"NoSubCategories",canSelectParentItems:true},
- {name:"unitCost",editorType:"spinner",step:0.01},
- {name:"inStock"},
- {name:"nextShipment",useTextField:true,editorType:"date"},
- {name:"savebtn",editorType:"button",align:"center",
- width:100,colSpan:4,title:"SaveItem",click:"editForm.saveData()"}
- ],
- width:650,
- numCols:4,
- colWidths:[100,200,100,200],
- margin:25,
- cellPadding:5,
- autoFocus:false
- });
- isc.Label.create({
- ID:"editorMessage",
- autoDraw:false,
- width:"100%",
- height:"100%",
- align:"center",
- contents:"Selectarecordtoedit,oracategorytoinsertanewrecordinto"
- });
- isc.TabSet.create({
- ID:"itemDetailTabs",
- tabs:[
- {title:"View",pane:itemViewer,ID:"viewTab",width:70,icon:"demoApp/icon_view.png"},
- {title:"Edit",pane:editForm,ID:"editTab",width:70,icon:"demoApp/icon_edit.png"}
- ],
- tabSelected:"itemList.updateDetails()",
- clearDetails:function(){
- varselectedTab=this.getSelectedTabNumber();
- if(selectedTab==0){
- itemViewer.setData();
- }elseif(selectedTab==1){
- if(categoryTree.getSelectedRecord()!=null){
- this.updateTab("editTab",editForm);
- editForm.editNewRecord({category:categoryTree.getSelectedRecord().categoryName});
- }else{
- this.updateTab("editTab",editorMessage);
- }
- }
- }
- });
- //Defineapplicationlayout
- //---------------------------------------------------------------------
- isc.HLayout.create({
- ID:"pageLayout",
- width:"100%",
- height:"100%",
- layoutMargin:20,
- members:[
- isc.SectionStack.create({
- ID:"leftSideLayout",
- width:280,
- showResizeBar:true,
- visibilityMode:"multiple",
- animateSections:true,
- sections:[
- {title:"OfficeSupplyCategories",autoShow:true,items:[categoryTree]},
- {title:"Instructions",autoShow:true,items:[helpCanvas]}
- ]
- }),
- isc.SectionStack.create({
- ID:"rightSideLayout",
- visibilityMode:"multiple",
- animateSections:true,
- sections:[
- {title:"FindItems",autoShow:true,items:[
- isc.Canvas.create({
- ID:"findPane",
- height:60,
- overflow:"auto",
- styleName:"defaultBorder",
- children:[findForm,findButton]
- })
- ]},
- {title:"OfficeSupplyItems",autoShow:true,items:[itemList]},
- {title:"ItemDetails",autoShow:true,items:[itemDetailTabs]}
- ]
- })
- ]
- });
- isc.Page.setEvent("load","pageLayout.draw()");
- //Customlogic:
- //Whenshowingoptionsinthecombo-box,onlyshowtheoptionsfromtheselectedcategory
- //ifappropriate
- findForm.getItem("itemName").addProperties({
- getPickListFilterCriteria:function(){
- varcriteria=this.Super("getPickListFilterCriteria",arguments);
- if(this.form.getValue('findInCategory')&&categoryTree.selection.anySelected()){
- criteria.category=categoryTree.getSelectedRecord().categoryName;
- }
- returncriteria
- }
- });
- categoryTree.fetchData();
- java代碼
- DAO層
- packageisc.java.Dao;
- importisc.java.Module.supplyItem;
- importjava.util.List;
- importorg.hibernate.SessionFactory;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.orm.hibernate3.HibernateTemplate;
- importorg.springframework.stereotype.Repository;
- @Repository
- publicclasssupplyItem_Dao{
- privateHibernateTemplatehibernateTemplate;
- @SuppressWarnings("unused")
- @Autowired
- privatevoidsetHibernateTemplate(SessionFactorysessionFactory){
- this.hibernateTemplate=newHibernateTemplate(sessionFactory);
- }
- /*
- *functionfindAll
- *查询supplyItem表中所有记录
- *并以list形式返回
- *
- **/
- @SuppressWarnings("unchecked")
- publicList<supplyItem>findAll(Stringcategory){
- Stringhql="fromsupplyItemwherecategory='"+category+"'";
- Listlist=this.hibernateTemplate.find(hql);
- returnlist;
- }
- /*
- *根据category返回对应的记录
- **/
- @SuppressWarnings("unchecked")
- publicsupplyItemfindInfoByID(intitemID){
- supplyItemsupp=(supplyItem)this.hibernateTemplate.get(supplyItem.class,itemID);
- returnsupp;
- }
- /*
- *删除指定记录
- *
- **/
- publicvoiddeleteInfo(supplyItemsupp){
- this.hibernateTemplate.delete(supp);
- }
- /*
- *更新修改后的记录
- **/
- publicvoidupdateInfo(supplyItemsupp){
- this.hibernateTemplate.update(supp);
- }
- /*
- *增加记录
- **/
- publicvoidinsertInfo(supplyItemsupp){
- this.hibernateTemplate.save(supp);
- }
- }
- packageisc.java.Dao;
- importisc.java.Module.supplyCategory;
- importjava.util.List;
- importorg.hibernate.SessionFactory;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.orm.hibernate3.HibernateTemplate;
- importorg.springframework.stereotype.Repository;
- @Repository
- publicclasssupplyCategory_Dao{
- privateHibernateTemplatehibernateTemplate;
- @SuppressWarnings("unused")
- @Autowired
- privatevoidsetHibernateTemplate(SessionFactorysessionFactory){
- this.hibernateTemplate=newHibernateTemplate(sessionFactory);
- }
- @SuppressWarnings("unchecked")
- publicList<supplyCategory>findAll(StringparentId){
- Stringhql="fromsupplyCategorywhereparentId='"+parentId+"'";
- Listlist=this.hibernateTemplate.find(hql);
- returnlist;
- }
- }
- ENTITY層
- packageisc.java.Module;
- importjavax.persistence.Column;
- importjavax.persistence.Entity;
- importjavax.persistence.Id;
- importjavax.persistence.Table;
- @Entity
- @Table(name="supplyCategory")
- publicclasssupplyCategory{
- privateStringcategoryName;
- privateStringparentId;
- @Id
- @Column(name="categoryName")
- publicStringgetCategoryName(){
- returncategoryName;
- }
- publicvoidsetCategoryName(StringcategoryName){
- this.categoryName=categoryName;
- }
- @Column(name="parentId")
- publicStringgetParentId(){
- returnparentId;
- }
- publicvoidsetParentId(StringparentId){
- this.parentId=parentId;
- }
- }
- packageisc.java.Module;
- importjavax.persistence.Column;
- importjavax.persistence.Entity;
- importjavax.persistence.GeneratedValue;
- importjavax.persistence.Id;
- importjavax.persistence.Table;
- @Entity
- @Table(name="supplyItem")
- publicclasssupplyItem{
- privateintitemID;
- privateStringitemName;
- privatedoubleunitCost;
- privateStringSKU;
- privateStringdescription;
- privateStringcategory;
- privateStringinStock;
- privateStringnextShipment;
- @Id
- @GeneratedValue
- @Column(name="itemID")
- publicintgetItemID(){
- returnitemID;
- }
- publicvoidsetItemID(intitemID){
- this.itemID=itemID;
- }
- @Column(name="itemName")
- publicStringgetItemName(){
- returnitemName;
- }
- publicvoidsetItemName(StringitemName){
- this.itemName=itemName;
- }
- @Column(name="unitCost")
- publicdoublegetUnitCost(){
- returnunitCost;
- }
- publicvoidsetUnitCost(doubleunitCost){
- this.unitCost=unitCost;
- }
- @Column(name="SKU")
- publicStringgetSKU(){
- returnSKU;
- }
- publicvoidsetSKU(Stringsku){
- SKU=sku;
- }
- @Column(name="description")
- publicStringgetDescription(){
- returndescription;
- }
- publicvoidsetDescription(Stringdescription){
- this.description=description;
- }
- @Column(name="category")
- publicStringgetCategory(){
- returncategory;
- }
- publicvoidsetCategory(Stringcategory){
- this.category=category;
- }
- @Column(name="instock")
- publicStringgetInStock(){
- returninStock;
- }
- publicvoidsetInStock(StringinStock){
- this.inStock=inStock;
- }
- @Column(name="nextShipment")
- publicStringgetNextShipment(){
- returnnextShipment;
- }
- publicvoidsetNextShipment(StringnextShipment){
- this.nextShipment=nextShipment;
- }
- }
- Service層
- packageisc.java.Service;
- importisc.java.Dao.supplyCategory_Dao;
- importisc.java.Module.supplyCategory;
- importjava.util.List;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.stereotype.Service;
- importorg.springframework.transaction.annotation.Transactional;
- @Service
- publicclasssupplyCategory_Service{
- privatesupplyCategory_DaosupplyCategory_dao;
- @Autowired
- publicvoidsetSupplyCategory_dao(supplyCategory_DaosupplyCategory_dao){
- this.supplyCategory_dao=supplyCategory_dao;
- }
- @Transactional("demoApp")
- publicList<supplyCategory>findAll(StringparentId){
- returnthis.supplyCategory_dao.findAll(parentId);
- }
- }
- packageisc.java.Service;
- importisc.java.Dao.supplyItem_Dao;
- importisc.java.Module.supplyItem;
- importjava.util.List;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.stereotype.Service;
- importorg.springframework.transaction.annotation.Transactional;
- @Service
- publicclasssupplyItem_Service{
- privatesupplyItem_DaosupplyItem_dao;
- @Autowired
- publicvoidsetSupplyItem_dao(supplyItem_DaosupplyItem_dao){
- this.supplyItem_dao=supplyItem_dao;
- }
- /*
- *使用声明式事物管理
- *在业务方法上进行@Transactional注解
- *将事物规则应用到业务逻辑中
- *demoApp为限定词*_*
- **/
- @Transactional("demoApp")
- publicList<supplyItem>findAll(Stringcategory){
- returnthis.supplyItem_dao.findAll(category);
- }
- @Transactional("demoApp")
- publicsupplyItemfindInfoByID(intitemID){
- returnthis.supplyItem_dao.findInfoByID(itemID);
- }
- @Transactional("demoApp")
- publicvoiddeleteInfo(intitemID){
- supplyItemsupp=this.supplyItem_dao.findInfoByID(itemID);
- this.supplyItem_dao.deleteInfo(supp);
- }
- @Transactional("demoApp")
- publicvoidupdateInfo(supplyItemsupp){
- this.supplyItem_dao.updateInfo(supp);
- }
- @Transactional("demoApp")
- publicvoidinsertInfo(supplyItemsupp){
- this.supplyItem_dao.insertInfo(supp);
- }
- }
- Web層
- packageisc.java.Web;
- importisc.java.Module.supplyCategory;
- importisc.java.Service.supplyCategory_Service;
- importjava.io.IOException;
- importjava.util.Enumeration;
- importjava.util.Iterator;
- importjava.util.List;
- importjavax.servlet.ServletOutputStream;
- importjavax.servlet.http.HttpServletRequest;
- importjavax.servlet.http.HttpServletResponse;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.stereotype.Controller;
- importorg.springframework.web.bind.annotation.RequestMapping;
- @Controller
- publicclasssupplyCategory_Controller{
- privatesupplyCategory_ServicesupplyCategory_service;
- @Autowired
- publicvoidsetSupplyCategory_service(
- supplyCategory_ServicesupplyCategory_service){
- this.supplyCategory_service=supplyCategory_service;
- }
- @SuppressWarnings("unchecked")
- @RequestMapping(value="demoApp/findTreeAll.action")
- publicvoidfindAll(HttpServletResponseresponse,HttpServletRequestrequest){
- StringparentId=request.getParameter("parentID");
- List<supplyCategory>list=this.supplyCategory_service.findAll(parentId);
- ServletOutputStreamsos=null;
- try{
- sos=response.getOutputStream();
- }catch(IOExceptione){
- //TODOAuto-generatedcatchblock
- e.printStackTrace();
- }
- StringBuffersbu=newStringBuffer();
- Iteratorita=(Iterator)list.iterator();
- while(ita.hasNext()){
- supplyCategorysupplycategory=(supplyCategory)ita.next();
- sbu.append("<country>");
- sbu.append("<categoryName>"+supplycategory.getCategoryName()+"</categoryName>");
- sbu.append("<parentId>"+supplycategory.getParentId()+"</parentId>");
- sbu.append("</country>");
- }
- try{
- sos.print("<?xmlversion='1.0'encoding='UTF-8'?><records>"+sbu.toString()+"</records>");
- }catch(IOExceptione){
- //TODOAuto-generatedcatchblock
- e.printStackTrace();
- }
- }
- }
- packageisc.java.Web;
- importisc.java.Module.supplyItem;
- importisc.java.Service.supplyItem_Service;
- importjava.io.IOException;
- importjava.util.Iterator;
- importjava.util.List;
- importjavax.servlet.ServletOutputStream;
- importjavax.servlet.http.HttpServletRequest;
- importjavax.servlet.http.HttpServletResponse;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.stereotype.Controller;
- importorg.springframework.web.bind.annotation.RequestMapping;
- @Controller
- publicclasssupplyItem_Controller{
- privatesupplyItem_ServicesupplyItem_service;
- @Autowired
- publicvoidsetSupplyItem_service(supplyItem_ServicesupplyItem_service){
- this.supplyItem_service=supplyItem_service;
- }
- /*
- *从数据库中提取数据以xml格式存储
- *
- **/
- @SuppressWarnings("unchecked")
- @RequestMapping(value="demoApp/findAll.action")
- publicvoidfindAll(HttpServletResponseresponse,HttpServletRequestrequest){
- Stringcategory=request.getParameter("category");//接受前台传过来的参数
- List<supplyItem>list=this.supplyItem_service.findAll(category);
- ServletOutputStreamsos=null;
- try{
- sos=response.getOutputStream();
- }catch(IOExceptione){
- e.printStackTrace();
- }
- StringBuffersbu=newStringBuffer();
- Iteratorita=(Iterator)list.iterator();
- while(ita.hasNext()){
- supplyItemsupplyitem=(supplyItem)ita.next();
- sbu.append("<country>");
- sbu.append("<itemID>"+supplyitem.getItemID()+"</itemID>");
- sbu.append("<itemName>"+supplyitem.getItemName()+"</itemName>");
- sbu.append("<unitCost>"+supplyitem.getUnitCost()+"</unitCost>");
- sbu.append("<SKU>"+supplyitem.getSKU()+"</SKU>");
- sbu.append("<description>"+supplyitem.getDescription()+"</description>");
- sbu.append("<category>"+supplyitem.getCategory()+"</category>");
- sbu.append("<inStock>"+supplyitem.getInStock()+"</inStock>");
- sbu.append("<nextShipment>"+supplyitem.getNextShipment()+"</nextShipment>");
- sbu.append("</country>");
- }
- try{
- sos.print("<?xmlversion='1.0'encoding='UTF-8'?><records>"+sbu.toString()+"</records>");
- }catch(IOExceptione){
- e.printStackTrace();
- }
- }
- @RequestMapping(value="demoApp/deleteInfo.action")
- publicvoiddeleteInfo(HttpServletRequestrequest){
- intitemID=Integer.parseInt(request.getParameter("itemID"));
- System.out.println("test======================"+itemID);
- this.supplyItem_service.deleteInfo(itemID);
- }
- @RequestMapping(value="demoApp/updateInfo.action")
- publicvoidupdateInfo(HttpServletRequestrequest){
- intitemID=Integer.parseInt(request.getParameter("itemID"));
- supplyItemsupp=this.supplyItem_service.findInfoByID(itemID);
- supp.setSKU(request.getParameter("SKU"));
- supp.setCategory(request.getParameter("category"));
- supp.setDescription(request.getParameter("description"));
- supp.setInStock(request.getParameter("inStock"));
- supp.setItemName(request.getParameter("itemName"));
- supp.setNextShipment(request.getParameter("nextShipment"));
- Strings=request.getParameter("unitCost");
- supp.setUnitCost(Double.parseDouble(s));
- this.supplyItem_service.updateInfo(supp);
- }
- @RequestMapping(value="demoApp/insertInfo.action")
- publicvoidinsertInfo(HttpServletRequestrequest){
- supplyItemsupp=newsupplyItem();
- supp.setCategory(request.getParameter("category"));
- supp.setSKU(request.getParameter("SKU"));
- supp.setDescription(request.getParameter("description"));
- supp.setInStock(request.getParameter("inStock"));
- supp.setItemName(request.getParameter("itemName"));
- supp.setNextShipment(request.getParameter("nextShipment"));
- supp.setUnitCost(Double.parseDouble(request.getParameter("unitCost")));
- this.supplyItem_service.insertInfo(supp);
- }
- }
- Xml
- App-config.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
- <!--Scanstheclasspathofthisapplicationfor@Componentstodeployasbeans-->
- <!--規約所有進行掃描的類,以完成Bean創建和自動依賴注入功能-->
- <context:component-scanbase-package="isc.java.*"/>
- <!--<context:annotation-config/>-->
- <!--Configuresthe@Controllerprogrammingmodel-->
- <mvc:annotation-driven/>
- <!--misc-->
- <beanid="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <propertyname="viewClass"value="org.springframework.web.servlet.view.JstlView"/>
- <propertyname="suffix"value=".action"/>
- </bean>
- <!--ConfiguresHibernate-DatabaseConfig-->
- <importresource="db-config.xml"/>
- </beans>
- Db-config.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
- <beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <propertyname="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>
- <propertyname="url"><value>jdbc:sqlserver://10.1.100.215:1433;DatabaseName=email</value></property>
- <propertyname="username"><value>dev</value></property>
- <propertyname="password"><value>12345678aA</value></property>
- </bean>
- <beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <propertyname="dataSource"><reflocal="dataSource"/></property>
- <propertyname="packagesToScan"value="isc.java.*"/>
- <propertyname="hibernateProperties">
- <props>
- <propkey="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
- <propkey="hibernate.show_sql">true</prop>
- <!--<propkey="hibernate.hbm2ddl.auto">update</prop>-->
- <propkey="hibernate.format_sql">true</prop>
- </props>
- </property>
- </bean>
- <!--TransactionmanagerforasingleHibernateSessionFactory(alternativetoJTA)-->
- <tx:annotation-driven/>
- <beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <propertyname="sessionFactory"><reflocal="sessionFactory"/></property>
- <qualifiervalue="demoApp"/><!--限定词-->
- </bean>
- </beans>