汽車租賃管理開發流程的博客

在這個暑假假期中,咱們團隊作了一個汽車的租賃管理的網站,咱們團隊採用分工的開發的方式,其中史秀源負責這個系統的統籌管理,羅竣元負責汽車管理的模塊,譚枝敬負責前臺職工管理,盧偉斌負責前臺管理,閆龍飛負責後臺的管理。咱們的分工的系統是放在碼html

雲上(https://git.oschina.net/nn839155963)和用smartgit進行項目的管理的,如今咱們的car 項目截圖以下,每一個成員將本身修改的內容pull到碼雲上,其餘成員實時更新網站上的東西,整個團隊就能夠知道整個項目的開發進度,從而實現了對項目開發過程的精確的管理。前端

 

管理java

 

 

 

雲上mysql

 

 

咱們這個系統採用ssm框架,就是Spring ,SpringMVC ,mybstis 的簡稱,mybatis的做用做爲一個鏈接數據庫的框架,能夠很好配置鏈接好數據庫, 有mybatis,咱們對數據庫增刪改查的操做更爲簡便了。SSM框架是目前網站開發中比較經常使用和比較流行的框架,其中git

ssm框架有六個層次controller ,dao層,model層,service層,mapping層,serviceImp層,咱們的工程相關的截圖以下;web

 

相關的六個層次的截圖以下其中,mybatis 用來鏈接數據庫,有mybatis,咱們對數據庫增刪改查的操做更爲簡便了。SSM框架,咱們用MAVEN工具對他們進行管理,maven 工具的主要做用就是爲咱們的工程自動配置好咱們所需的架包,是經過POM.xml 文件進行依懶管理的。pom.xml的代碼以下,配置了相關的依賴的管理;spring

其中pom.xml 配置文件的代碼以下sql

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.zzty</groupId>
	<artifactId>car</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>car Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<properties>
		<!-- spring版本號 -->
		<spring.version>4.0.2.RELEASE</spring.version>
		<!-- mybatis版本號 -->
		<mybatis.version>3.1.1</mybatis.version>
		<!-- log4j日誌文件管理包版本 -->
		<slf4j.version>1.7.7</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>ooxml-schemas</artifactId>
			<version>1.0</version>
		</dependency>

		<dependency>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
			<version>1.6.1</version>
		</dependency>

		<dependency>
			<groupId>net.sourceforge.jexcelapi</groupId>
			<artifactId>jxl</artifactId>
			<version>2.6.12</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<!-- 表示開發的時候引入,發佈的時候不會加載此包 -->
			<scope>test</scope>
		</dependency>
		<!-- spring核心包 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- mybatis核心包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>
		<!-- mybatis/spring包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.1.0</version>
		</dependency>
		<!-- 導入java ee jar 包 -->
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
		</dependency>
		<!-- 導入Mysql數據庫連接jar包 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.30</version>
		</dependency>
		<!-- 導入dbcp的jar包,用來在applicationContext.xml中配置數據庫 -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.2.2</version>
		</dependency>
		<!-- JSTL標籤類 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- 日誌文件管理包 -->
		<!-- log start -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>${log4j.version}</version>
		</dependency>


		<!-- 格式化對象,方便輸出日誌 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.41</version>
		</dependency>


		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<!-- log end -->
		<!-- 映入JSON -->
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>1.9.13</version>
		</dependency>
		<!-- 上傳組件包 -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.9</version>
		</dependency>
		<!-- QRcode -->
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>core</artifactId>
			<version>3.2.1</version>
		</dependency>
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>javase</artifactId>
			<version>3.2.1</version>
		</dependency>

	</dependencies>
	<build>
		<finalName>car</finalName>
	</build>
</project>

  2 如今就是配置resources  下面的四個文件數據庫

 

jdbc.properties   鏈接你的數據庫的配置,還有一些做用本身理解。apache

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.31.242:3306/car_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
username=car
password=root
#定義初始鏈接數
initialSize=0
#定義最大鏈接數
maxActive=20
#定義最大空閒
maxIdle=20
#定義最小空閒
minIdle=1
#定義最長等待時間
maxWait=60000
imagePath=D:/sts/workspace/car/src/main/webapp/resources/image/

log4.properties   用來記錄工程運行調試的記錄什麼的。

#定義LOG輸出級別
log4j.rootLogger=INFO,Console,File
#定義日誌輸出目的地爲控制檯
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
#能夠靈活地指定日誌輸出格式,下面一行是指定具體的格式
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n

#文件大小到達指定尺寸的時候產生一個新的文件
log4j.appender.File = org.apache.log4j.RollingFileAppender
#指定輸出目錄

#定義文件最大大小
log4j.appender.File.MaxFileSize = 10MB
# 輸出因此日誌,若是換成DEBUG表示輸出DEBUG以上級別日誌
log4j.appender.File.Threshold = ALL
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

3 spring mvc .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" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
                        http://www.springframework.org/schema/context  
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                        http://www.springframework.org/schema/mvc  
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <!-- 自動掃描該包,使SpringMVC認爲包下用了@controller註解的類是控制器 -->
    <context:component-scan base-package="car.*" />
        <!-- 引入配置文件 -->
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties" />
    </bean>
    <!--避免IE執行AJAX時,返回JSON出現下載文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 啓動SpringMVC的註解功能,完成請求和註解POJO的映射 -->
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" />    <!-- JSON轉換器 -->
            </list>
        </property>
    </bean>
    <!-- 定義跳轉的文件的先後綴 ,視圖模式配置-這裏的配置個人理解是自動給後面action的方法return的字符串加上前綴和後綴,變成一個 可用的url地址-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    
    <!-- 配置文件上傳,若是沒有使用文件上傳能夠不用配置,固然若是不配,那麼配置文件中也沒必要引入上傳組件包 -->
    <bean id="multipartResolver"  
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <!-- 默認編碼 -->
        <property name="defaultEncoding" value="utf-8" />  
        <!-- 文件大小最大值 -->
        <property name="maxUploadSize" value="10485760000" />  
        <!-- 內存中的最大值 -->
        <property name="maxInMemorySize" value="40960" />  
    </bean> 

</beans>

4 spring mybatis.xml  他的做用就是就Spring 和Mybatis 整合起來。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
                        http://www.springframework.org/schema/context  
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                        http://www.springframework.org/schema/mvc  
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <!-- 自動掃描 -->
    <context:component-scan base-package="car.*" />
    <!-- 引入配置文件 -->
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties" />
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${driver}" />
        <property name="url" value="${url}" />
        <property name="username" value="${username}" />
        <property name="password" value="${password}" />
        <!-- 初始化鏈接大小 -->
        <property name="initialSize" value="${initialSize}"></property>
        <!-- 鏈接池最大數量 -->
        <property name="maxActive" value="${maxActive}"></property>
        <!-- 鏈接池最大空閒 -->
        <property name="maxIdle" value="${maxIdle}"></property>
        <!-- 鏈接池最小空閒 -->
        <property name="minIdle" value="${minIdle}"></property>
        <!-- 獲取鏈接最大等待時間 -->
        <property name="maxWait" value="${maxWait}"></property>
    </bean>

    <!-- spring和MyBatis完美整合,不須要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自動掃描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:car/mapping/*.xml"></property>
    </bean>

    <!-- DAO接口所在包名,Spring會自動查找其下的類 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="car.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

</beans>

 5.還有webapp 下面的WEB-INF下面的web.xml 的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Archetype Created Web Application</display-name>
    <!-- Spring和mybatis的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
    </context-param>
    <!-- 編碼過濾器 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Spring監聽器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 防止Spring內存溢出監聽器 -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
    <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <!-- 此處能夠能夠配置成*.do,對應struts的後綴習慣 -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
    <!-- 配置SESSION超時,單位是分鐘 -->
    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>

</web-app>

如今就是將ssm框架搭好起來了,接下來咱們團隊的工做就是進行建數據庫的工做,咱們在咱們其中一個成員的電腦創建一個數據庫做爲服務器,咱們其餘的成員經過使用一個局域網來訪問他的數據庫,從而造成了你們隨時修改數據的任何內容均可以及時讓團隊的其餘的成員看到數據的變化。咱們前期主要是建了六個表,後續還會添加新的表根據咱們系統的功能進行相應的擴展。

 

 

 

上面是建表相關的需求文檔,如今只是截取一小部分

三:如今將整個框架基本創建起來了,數據庫也搭建起來了,如今就是該是團隊奮鬥敲代碼的時間了,其中相關的代碼就是以數據爲中心,以jsp頁面爲顯示,對數據進行增刪改查的操做。整個系統不管作的多麼炫酷(使用了前端的有關的框架和模板),對於後端而言,都是對數據庫進行相關的增刪改查。如今就汽車租賃管理系統用戶的登錄和註冊的操做來證明咱們團隊的心得感覺。咱們直接以相關的代碼來一一講解和說明,廢話很少說,直接上代碼!

1 首先是model 層,Mapping層,Dao層,service層,serviceImp層,controller層來講明。首先是model 層,這個Customer層定義了用戶相關的屬性。

package car.model;

public class Customer {
    private Integer id;

    private String username;

    private String pwd;

    private String idcard;

    private Integer keyid;

    private String name;

    private String phone;

    private String keyname;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd == null ? null : pwd.trim();
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard == null ? null : idcard.trim();
    }

    public Integer getKeyid() {
        return keyid;
    }

    public void setKeyid(Integer keyid) {
        this.keyid = keyid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public String getKeyname() {
        return keyname;
    }

    public void setKeyname(String keyname) {
        this.keyname = keyname == null ? null : keyname.trim();
    }
}

 

2.再次就是dao 層,他定義對Customer這個對象相關的方法,這些能夠看出也就是相應的增刪改查的操做。這就輔證剛纔所陳述的語句。

package car.dao;

import car.model.Customer;

public interface CustomerMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Customer record);

    int insertSelective(Customer record);

    Customer selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Customer record);

    int updateByPrimaryKey(Customer record);
    
    int updateByUserName(Customer record);
    
    Customer selectByName(String username);
}

 

3就是Mapping層,這個層主要鏈接數據的操做,就是一條條對數據庫的數據進行相關的增刪改查的操做的SQL語句,這些SQL語句都是基於Mybatis框架進行相應的封裝而寫出來。 在咱們數據庫的知識中,以下代碼咱們也能夠看得懂是對數據進行增刪改查的操做。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="car.dao.CustomerMapper" >
  <resultMap id="BaseResultMap" type="car.model.Customer" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="username" property="username" jdbcType="VARCHAR" />
    <result column="pwd" property="pwd" jdbcType="VARCHAR" />
    <result column="idcard" property="idcard" jdbcType="VARCHAR" />
    <result column="keyid" property="keyid" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="phone" property="phone" jdbcType="VARCHAR" />
    <result column="keyname" property="keyname" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, username, pwd, idcard, keyid, name, phone, keyname
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from customer
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from customer
    where username = #{username,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from customer
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="car.model.Customer" >
    insert into customer (id, username, pwd, 
      idcard, keyid, name, 
      phone, keyname)
    values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, 
      #{idcard,jdbcType=VARCHAR}, #{keyid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{keyname,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="car.model.Customer" >
    insert into customer
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="username != null" >
        username,
      </if>
      <if test="pwd != null" >
        pwd,
      </if>
      <if test="idcard != null" >
        idcard,
      </if>
      <if test="keyid != null" >
        keyid,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="phone != null" >
        phone,
      </if>
      <if test="keyname != null" >
        keyname,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="username != null" >
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="pwd != null" >
        #{pwd,jdbcType=VARCHAR},
      </if>
      <if test="idcard != null" >
        #{idcard,jdbcType=VARCHAR},
      </if>
      <if test="keyid != null" >
        #{keyid,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null" >
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="keyname != null" >
        #{keyname,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="car.model.Customer" >
    update customer
    <set >
      <if test="username != null" >
        username = #{username,jdbcType=VARCHAR},
      </if>
      <if test="pwd != null" >
        pwd = #{pwd,jdbcType=VARCHAR},
      </if>
      <if test="idcard != null" >
        idcard = #{idcard,jdbcType=VARCHAR},
      </if>
      <if test="keyid != null" >
        keyid = #{keyid,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null" >
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="keyname != null" >
        keyname = #{keyname,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="car.model.Customer" >
    update customer
    set username = #{username,jdbcType=VARCHAR},
      pwd = #{pwd,jdbcType=VARCHAR},
      idcard = #{idcard,jdbcType=VARCHAR},
      keyid = #{keyid,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      keyname = #{keyname,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByUserName" parameterType="car.model.Customer" >
    update customer
    set username = #{username,jdbcType=VARCHAR},
      idcard = #{idcard,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR}
    where username = #{username,jdbcType=VARCHAR}
  </update>
</mapper>

 

4 就是Service 層,service層的主要的做用,就是使用藉口interface來定義相關的方法。

package car.service;

import java.util.List;

import car.model.Car;

public interface CarService {
       int deleteByPrimaryKey(Integer id);

        int insert(Car record);

        int insertSelective(Car record);

        Car selectByPrimaryKey(Integer id);

        int updateByPrimaryKeySelective(Car record);

        int updateByPrimaryKey(Car record);
        
        Car selectByName(String username);
        
        List<Car> getAllCar();
    

}

5 serviceImp層,主要是對上面service 層的接口方法進行實現,也就是咱們常說的接口的實現類,如今經過框架將他封裝了起來罷了。實現service 層,主要使用Springmvc 框架的註解@service h和

 @Resource 相關框架的操做。
package car.serviceImp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import car.dao.CarMapper;
import car.model.Car;
import car.service.CarService;

@Service("carService")
public class CarServiceImp implements CarService {
    @Resource
    private CarMapper carMapper;
    public int deleteByPrimaryKey(Integer id) {
        // TODO Auto-generated method stub
        return this.carMapper.deleteByPrimaryKey(id);
    }

    public int insert(Car record) {
        // TODO Auto-generated method stub
        return this.carMapper.insert(record);
    }

    public int insertSelective(Car record) {
        // TODO Auto-generated method stub
        return this.carMapper.insertSelective(record);
    }

    public Car selectByPrimaryKey(Integer id) {
        // TODO Auto-generated method stub
        return this.carMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Car record) {
        // TODO Auto-generated method stub
        return this.carMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(Car record) {
        // TODO Auto-generated method stub
        return this.carMapper.updateByPrimaryKey(record);
    }

    public Car selectByName(String username) {
        // TODO Auto-generated method stub
        return this.selectByName(username);
        
    }

    public List<Car> getAllCar() {
        // TODO Auto-generated method stub
        return this.carMapper.getAllCar();
    }

}

6 接下來就是核心Controller 了,他實現整個系統的業務的邏輯,能夠看出最後相關的登錄驗證(至關於對數據進行查詢)和註冊(至關於對數據庫進行添加)以及各類頁面的跳轉都是在Controller進行控制和處理的,Controller至關整個系統的大腦。

package car.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sun.mail.handlers.message_rfc822;

import car.model.Car;
import car.model.Customer;
import car.model.ReservationOrder;
import car.model.Worker;
import car.service.CarService;
import car.service.CustomerService;
import car.service.ReservationOrderService;
import car.service.WorkerService;

@Controller
@RequestMapping("/front")
public class FrontPlatForm {
    @Resource
    private CustomerService customerService;
    @Resource
    private ReservationOrderService reservationOrderService;
    @Resource
    private WorkerService workerService;
    @Resource
    private CarService carService;
    
    @RequestMapping("/toindex")
    public ModelAndView toindex(){
        ModelAndView view = new ModelAndView("frontPlatForm/index");
        return view;
        
    }
    @RequestMapping("/tologin")
    public ModelAndView toLogin(){
        ModelAndView view = new ModelAndView("frontPlatForm/login");
        return view;
    }
    

    
    @RequestMapping("/login")
    public ModelAndView login(HttpServletRequest request){
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        if(username!=null&&pwd!=null){
            Customer customer = this.customerService.selectByName(username);
            if(customer!=null&&pwd.equals(customer.getPwd())){
                HttpSession session = request.getSession();
                session.setAttribute("customer", customer);
                ModelAndView view = new ModelAndView("frontPlatForm/customerInfo");
                return view;
            }
        }
        return new ModelAndView("frontPlatForm/login");
        
    }
    
    @RequestMapping("/doregister")
    public String doregister(HttpServletRequest request, Model model) {
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        String pwd1 = request.getParameter("pwd1");
        if (username!=""&&pwd!=""&&pwd1!="")
        {
            if(pwd.equals(pwd1)){
            Customer customer = new Customer();
            customer.setUsername(username);
            customer.setPwd(pwd);
            int c = this.customerService.insertSelective(customer);
            if (c > 0) {
                HttpSession session = request.getSession();
                session.setAttribute("customer", customer);
            }
          }
        }
        return "frontPlatForm/login";
    }
    
    //跳轉到帳號信息頁面
    @RequestMapping("/toCustomerInfo")
    public ModelAndView CustomerInfo(){
        ModelAndView view = new ModelAndView("frontPlatForm/customerInfo");
        return view;
    }
    
    //修改用戶信息
    @RequestMapping("/changeInfo")
    public ModelAndView changeInfo(HttpServletRequest request){
        String username = getCustomer(request).getUsername();
        String idcard = request.getParameter("idcard");
        String name =  request.getParameter("name");
        String phone =  request.getParameter("phone");
        Customer customer = new Customer();
        customer.setUsername(username);
        customer.setIdcard(idcard);
        customer.setName(name);
        customer.setPhone(phone);
        int update = this.customerService.updateByUserName(customer);
        System.out.println(update);
        if (update > 0) {
            String message = "修改爲功";
            request.getSession().setAttribute("mes", message);
        }
        HttpSession session = request.getSession();
        session.setAttribute("customer", customer);
        ModelAndView view = new ModelAndView("frontPlatForm/customerInfo");
        return view;
        
    }

    // 密碼修改界面
        @RequestMapping("/changePwd")
        public ModelAndView changePwd(HttpServletResponse response, HttpServletRequest request, Model model)
                throws IOException {
            String userName = getCustomer(request).getUsername();
            String password = request.getParameter("password");
            String oldpass = request.getParameter("oldpass");
            Customer customer = new Customer();
            customer = this.customerService.selectByName(userName);
            if (customer.getPwd().equals(oldpass) && !(oldpass.equals(password))) {
                customer.setName(userName);
                customer.setPwd(password);
                this.customerService.updateByUserName(customer);
                ModelAndView view = new ModelAndView("frontPlatForm/login");
                return view;
            } else if (userName != null && password == null && oldpass == null) {
                String message = "";
                request.getSession().setAttribute("mes", message);
            } else if (password.equals(oldpass)) {

                String message = "新密碼不能與原密碼相同";
                request.getSession().setAttribute("mes", message);
            } else {
                String message = "原密碼錯誤";
                request.getSession().setAttribute("mes", message);
                }
            return new ModelAndView("frontPlatForm/password");
        }
        
        
        //跳轉到預訂頁面
        @RequestMapping("/reservation")
        public ModelAndView reservation(HttpServletRequest request){
            String downPayment = request.getParameter("downPayment");
            String rentDate = request.getParameter("rentDate");
            String shReturnDate = request.getParameter("shReturnDate");
            String carId = request.getParameter("carId");
            if(downPayment!=null&&rentDate!=null&&shReturnDate!=null&&carId!=null){
                int customerId = getCustomer(request).getId();
            ReservationOrder reOrder = new ReservationOrder();
            reOrder.setDownPayment(Float.valueOf(downPayment));
            reOrder.setRentDate(rentDate);
            reOrder.setShreturnDate(shReturnDate);
            reOrder.setCarId(Integer.valueOf(carId));
            reOrder.setCustomerId(customerId);
            int insert = this.reservationOrderService.insertSelective(reOrder);
            }
            ModelAndView view = new ModelAndView("frontPlatForm/reservation");
            return view;
        }
        
        //顯示訂單信息頁面
        @RequestMapping("/reservationInfo")
        public ModelAndView reservationInfo(HttpServletRequest request,Model model){
            List<ReservationOrder> reOrder = this.reservationOrderService.selectByCustomerId(getCustomer(request).getId());
            ModelAndView view = new ModelAndView("frontPlatForm/reservationInfo");
            model.addAttribute("reOrder", reOrder);
            return view;
        }
        
        // 查找客戶信息
        public Customer getCustomer(HttpServletRequest request) {
            HttpSession session = request.getSession();
            String name = ((Customer) session.getAttribute("customer")).getUsername();
            Customer customer = customerService.selectByName(name);
            return customer;
        }
        
        //職工信息管理頁面
        @RequestMapping("/workerManage")
        public ModelAndView getWorker(HttpServletRequest request,Model model){
            List<Worker> worker = workerService.selectAll();
            model.addAttribute("worker", worker);
            ModelAndView view = new ModelAndView("administrator/workerInfo");
            return view;
        }
        
        //添加職工信息
        @RequestMapping("/addWorker")
        public void addWorker(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException{
            String name = request.getParameter("name");
            String pwd = request.getParameter("pwd");
            String idcard = request.getParameter("idcard");
            String keyname = request.getParameter("keyname");
            String keyid = request.getParameter("keyid");
            if(name!=null&&idcard!=null&&keyname!=null&&keyid!=null){
            Worker worker1 = new Worker();
            worker1.setName(name);
            worker1.setPwd(pwd);
            worker1.setIdcard(idcard);
            worker1.setKeyname(keyname);
            worker1.setKeyid(Integer.valueOf(keyid));
            int insert = workerService.insert(worker1);
            if(insert>0){
                List<Worker> worker = workerService.selectAll();
                model.addAttribute("worker", worker);
                response.sendRedirect("workerManage");
                }
            }
        }
        
        //刪除職工信息
        @RequestMapping("/deleteWorker")
        public ModelAndView deleteWorker(HttpServletRequest request, Model model) {
            String items = request.getParameter("delitems");
            List<String> delList = new ArrayList<String>();
            String[] strs = items.split(",");
            for (String str : strs) {
                delList.add(str);
            }
            this.workerService.batchDeletes(delList);
            List<Worker> worker = this.workerService.selectAll();
            model.addAttribute("worker", worker);
            ModelAndView view = new ModelAndView("administrator/workerInfo");
            return view;
        }
        
        //根據編號查找職工
        @RequestMapping(value="/selectWorker", method = RequestMethod.POST)
        @ResponseBody
        public Worker selectWorker(HttpServletRequest request,Model model){
            String id = request.getParameter("id");
            Worker worker = new Worker();
            if(id!=null){
                worker = this.workerService.selectByPrimaryKey(Integer.valueOf(id));
            }
            HttpSession session = request.getSession();
            session.setAttribute("worker1",worker);
            model.addAttribute("worker1", worker);
            return worker;
        }
        
        
        //修改職工信息
        @RequestMapping("/updateWorker")
        public void updateWorker(HttpServletResponse response,HttpServletRequest request,Model model) throws IOException{
            String id = request.getParameter("id");
            String name = request.getParameter("name");
            String pwd = request.getParameter("pwd");
            String idcard = request.getParameter("idcard");
            String keyname = request.getParameter("keyname");
            String keyid = request.getParameter("keyid");
            int update = 0;
            if(id!=null&&name!=null&&idcard!=null&&keyname!=null&&keyid!=null){
                Worker worker1 = new Worker();
                worker1.setId(Integer.valueOf(id));
                worker1.setName(name);
                worker1.setPwd(pwd);
                worker1.setIdcard(idcard);
                worker1.setKeyname(keyname);
                worker1.setKeyid(Integer.valueOf(keyid));
                update = workerService.updateByPrimaryKey(worker1);
            }
            if(update>0){
            List<Worker> worker = this.workerService.selectAll();
            model.addAttribute("worker", worker);
            response.sendRedirect("workerManage");
            }
        }
        
        //管理員顯示訂單信息頁面
                @RequestMapping("/adminReInfo")
                public ModelAndView adminReInfo(HttpServletRequest request,Model model){
                    List<ReservationOrder> reOrder = this.reservationOrderService.selectAll();
                    ModelAndView view = new ModelAndView("administrator/reservationInfo");
                    model.addAttribute("reOrder", reOrder);
                    return view;
                }
        
        //管理員顯示車輛信息
                @RequestMapping("/adminCarInfo")
                public ModelAndView adminCarInfo(HttpServletRequest request,Model model){
                    List<Car> car = this.carService.getAllCar();
                    ModelAndView view = new ModelAndView("administrator/carInfo");
                    model.addAttribute("car", car);
                    return view;
                    
                }
        
}

綜上所述,相信老師對於咱們所用的這個SSM 框架有了大體的瞭解吧,我如今是拿登錄註冊來進行說明,那麼其餘後續汽車的管理也是運用上面的六個Controller層進行相關的增刪改查。咱們如今給出咱們這個項目大體代碼目錄的截圖(d固然這些代碼也會逐漸增長,如今功能尚未完善到最後)

四:代碼上了一大堆,那麼如今來看看咱們實現登錄註冊以及後臺汽車管理的真實網頁上截圖。

 

1 如今customer 表有以下的數據

2 咱們如今來看看咱們的登錄頁面 ,咱們如今使用839155963@qq.com的帳號進行登錄

 

3 登錄進去的頁面以下,進入到顧客的帳號就能夠對本身的信息進行相應的添加修改,瀏覽查看車輛的信息以及進行預訂車輛的相關操做,均可以進行。

 

 

 

 

4 好比咱們對本身的信息進行修改和添加

 

6 能夠看見數據庫的數據已經更新了

 

 

 

7咱們在看看修改密碼的功能 將密碼修改成123456

8 數據庫密碼已經更新了

 

9 查看汽車的信息

 

 

 

10 點擊查看詳情鏈接能夠進入汽車的詳情頁

 

 

 

 

 

11 相關的汽車詳情頁 如今尚未徹底作好,到時候這個頁面將提供汽車的詳細的信息和相關的圖片展現 以及汽車的預約頁都將在這個頁面實現

 

12  再說說另一個在本系統權限的 最大的管理員的頁面

13 管理並無註冊的功能,他只有註冊的功能,管理員的數據是直接操做數據庫後臺直接插進去,系統只是提供一個登錄的功能給他而已。意思是並非每一個人均可以註冊成爲系統的管理員

管理員能夠對汽車管理和相關的職工的信息進行修改添加的增刪改查的操做

最後的吧,相關的頁面展現到答辯再一一進行回答,相關的工做拖得有點晚,才致使這篇博客拖得這麼晚,不過我想既然決定寫好,就要將它寫的比較好,起碼對的起老師花費寶貴的時間來爲咱們進行審閱

五:團隊相關的心得體會

    經過了這個汽車項目的鍛鍊,咱們你們都一致的認爲在軟件的開發的過程當中,團隊協做以及精誠合做真的很重要,一我的的力量是很是有限的,可是團隊團結起來的力量是強大的。團隊合做是咱們開發一個項目的不二之選。

其次,開發的過程咱們遇到不少的困難,咱們經過相互學習以及利用身邊的書籍網上豐富的資源,解決掉項目很多的問題,經過咱們同窗之間的交流,思路的不一樣可讓咱們收穫頗多。善於學習別人的長處和利用身邊的網上的資源,對於咱們提升咱們的學習能力以及咱們自身的技術真的有很大的幫助。其次,開發項目要選擇合適框架以及好的良好的碼雲等相關輔助相關的工具。對於咱們開發的速度有很好的促進的做用,總而言之,咱們團隊須要經過這個汽車的租賃的項目,來自學吃透SSM框架的相關的內容,這應該就是咱們作這個項目的最大的收穫,最後的,增強咱們團隊總體的前端的頁面的美化,雖說本身作的頁面本身都不想看,更況且是用戶尼,因此學習的道路永遠都是在路上,並無所謂的終點。

 

                                                                                                                                                                                                                                                           謝謝各位花費寶貴的時間欣賞完本文,謝謝!

相關文章
相關標籤/搜索