短學期(3)第三次感悟
1.修改數據的各項配置都配置好之後,點擊修改還是不能修改客戶信息,跳出了下圖這個界面,百度之後顯示這個錯誤是指數組超出索引,數組越界了,但還是不會修改
把<s:action name="typeAction" id="list"></s:action>刪掉之後
還是出現了這個錯誤,之後錯誤頁面中顯示CustServiceImpl.java中的32行錯誤,即這邊的findCustById還沒配return的值
2.在dao中把所有的增刪查改都定義了接口,實現接口要實現裏面所有的方法,通過SQL語句把查詢的列表全部顯示出來,通過類的對象的id號把客戶的一個對象顯示出來,這邊的接口實現都是繼承的
ublic class UpdatePreviewCustAction extends ActionSupport
接受前端傳過來的請求,
網頁中404的錯誤是路徑錯誤,500的錯誤是屬性錯誤
3.service要調用dao
在custInfo中,要先預覽,才能修改,所以此處應先指向預覽即updatePreviewCust
4.修改客戶信息時還是不能講客戶信息修改完成
是由於UpdateCustAction.java中的方法寫成了customer,導致不能修改成功
5.新增客戶時,即使新增了客戶的電話號碼,但還是不能在查詢時顯示出來
在cust.java中添加了下面代碼之後,還是不可以
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
後來在Cust.hbm.xml中<property name="telephone" type="string" column="telephone" length="20"/>這段代碼移動到id中之後,再新增客戶信息時,就能顯示客戶的電話號碼了,但是由於之前的客戶信息都是沒有加電話號碼代碼之前就增加的,所以還是不能顯示電話號碼。
6.之後我們開始做小組項目,我們主要做庫存管理
做項目的步驟為:1.搭建環境SSH
2.寫配置文件
3.分層實現:Bean:Java.class,xxx.hbm.xml
Dao:Dao接口,Dao實現
Service:service接口,service實現
Action:Action→Service→Dao
hql語句不是SQL語句,需要寫String hql = "from Cust cust order by cust.id desc";
訂單管理,可以分為訂單編號,商品名稱,商品價格,支付方式,客戶姓名,聯系方式,送貨地址。這邊的支付方式有在線支付,微信,貨到付款等,時間可以有兩種表達方式:
1.Date yyyy/xxxxdd
2.time 時分秒
多線程,是指多個用戶一起點擊某個功能時,每個用戶都可以使用
7.庫存管理的需求分析
就像超市裏面,老板要知道哪些貨物要下架,哪些貨物要增加,庫存等等
1.商品編號
2.商品名稱
3.商品價格
4.進貨渠道
5.進貨時間
這個問題是因為沒有將自己的工程hxytest部署到Tomcat 6.x中去
8.後來出現了Could not parse mapping document from input stream這個錯誤
映射錯誤,因為沒網,所以在applicationContext.xml中的鏈接mysql時鏈接不上
9.頁面中的修改沒必要再啟動一次
10.下面我們學習了如何自動生成Excel表格
配置完之後,還是不能生成Excel文件
後來發現是沒有在kcInfo.java中配置
function funExcel(){
location.href=‘generateExcel.action‘;
}
11.applicationContext.xml中的id是前端,class是後端,id與Struts中的class相對應,Struts中的name是自己取的名字,表示將做什麽動作
applicationContext.xml配置的是訪問路徑
index.jsp是網頁的代碼,即網頁腳本語言,用於嵌入到網頁中使用
學習了這麽多天,我大概學會了如何寫增刪改查使得可以在網頁中使用想這些操作,大概了解了ssh架構的搭建,還學會了如何將網頁中的表格生成excel文件
12.配置完之後的struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="kc" extends="struts-default">
<!-- 保存 -->
<action name="saveKc" class="kcSaveAction">
<result name="success" type="redirect">jsp/kcInfo.jsp</result>
<result name="input">/jsp/kcInfo.jsp</result>
</action>
<!-- 查詢 -->
<action name="listKc" class="kcListAction">
<result>/jsp/kcInfo.jsp</result>
</action>
<!-- 刪除 -->
<action name="delectKc" class="kcRemoveAction">
<result>/jsp/kcInfo.jsp</result>
</action>
<!-- 條件查詢 -->
<action name="findCdtKcList" class="findCdtAction">
<result>/jsp/kcInfo.jsp</result>
</action>
<!-- typeAcion下拉列表 -->
<action name="typeAction" class="typeAction">
<result></result>
</action>
<!-- 修改預覽 -->
<action name="updatePreviewkc" class="updatePreviewKcAction">
<result name="success">/jsp/kcUpdate.jsp</result>
</action>
<!-- 修改 -->
<action name="kcUpdate" class="updateKcAction">
<result name="success" type="redirect">listKc.action</result>
<result name="input">/jsp/kcUpdate.jsp</result>
</action>
<!-- 導出excel -->
<action name="generateExcel" class="generateExcelAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">filename="AllKc.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
</package>
</struts>
配置完之後的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!--數據庫-配置數據連接池 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/dbssh">
</property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
<property name="maxActive" value="100"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!--sessionFactory配置與管理 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/crm/bean/Kc.hbm.xml</value>
</list>
</property>
</bean>
<!--配置DAO-->
<bean id="kcDao" class="com.crm.impl.KcDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!--配置service -->
<bean id="kcService" class="com.crm.service.impl.KcServiceImpl">
<property name="kcDao" ref="kcDao"></property>
</bean>
<!--配置-新增saveAction -->
<bean id="kcSaveAction" class="com.crm.action.KcSaveAction">
<property name="service">
<ref bean="kcService"/>
</property>
</bean>
<!--配置-查詢listAction -->
<bean id="kcListAction" class="com.crm.action.KcListAction">
<property name="service" ref="kcService"></property>
</bean>
<!--配置-刪除removeAction -->
<bean id="kcRemoveAction" class="com.crm.action.KcRemoveAction">
<property name="service" ref="kcService"></property>
</bean>
<!--配置-條件查詢findCdtAction -->
<bean id="findCdtAction" class="com.crm.action.FindKcByCdtAction">
<property name="findCdtService" ref="kcService"></property>
</bean>
<!--配置-typeAction -->
<bean id="typeAction" class="com.crm.action.TypeAction">
</bean>
<!--配置-修改預覽updatePreviewAction -->
<bean id="updatePreviewKcAction" class="com.crm.action.UpdatePreviewKcAction">
<property name="updatePreviewKcService" ref="kcService"></property>
</bean>
<!--配置-修改updateKcAction -->
<bean id="updateKcAction" class="com.crm.action.UpdateKcAction">
<property name="updateKcService" ref="kcService"></property>
</bean>
<!-- 導出excel -->
<bean id="generateExcelAction" class="com.crm.action.GenerateExcelAction" scope="prototype">
<property name="excelService">
<ref bean="kcService"></ref>
</property>
</bean>
</beans>
配置完之後的index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>庫存管理界面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body background="images/2.jpg">
<body>
<br><br><br><br><br><br><br><br>
<!--<div><h1>庫存管理界面</h1><br></div>
<form action="" styles=""><font size="10" color="red">ssh-test-集成環境測試</font></form></center>-->
<center>
<div class="divcss5">
<center><h1><font color="red" size="7" face="Arabic Typesetting">操作列表</font></h1><br>
<s:a href="jsp/kcInfo.jsp"><font face="Aparajita"><strong><font size="5">庫存信息管理</font></strong></font></s:a><br><br>
<s:a href="jsp/kcInfo.jsp"><font face="Aparajita"><strong><font size="5">查詢庫存信息</font></strong></font></s:a></center>
</div><br>
</center>
</body>
</html>
還有其他的action中要對增刪查改動作的寫入,以及各個,全部配置完之後打開網頁之後出現的界面,還有點擊生成excel的按鍵出現的界面
可以根據自己的想法對此表格進行操作。
短學期(3)第三次感悟