汽车租赁管理开发流程的博客

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了汽车租赁管理开发流程的博客相关的知识,希望对你有一定的参考价值。

在这个暑假假期中,我们团队做了一个汽车的租赁管理的网站,我们团队采用分工的开发的方式,其中史秀源负责这个系统的统筹管理,罗竣元负责汽车管理的模块,谭枝敬负责前台职工管理,卢伟斌负责前台管理,闫龙飞负责后台的管理。我们的分工的系统是放在码

云上(https://git.oschina.net/nn839155963)和用smartgit进行项目的管理的,现在我们的car 项目截图如下,每个成员将自己修改的内容pull到码云上,其他成员实时更新网站上的东西,整个团队就可以知道整个项目的开发进度,从而实现了对项目开发过程的精确的管理。

 

管理技术分享

 

 

 

云上技术分享

 

 

我们这个系统采用ssm框架,就是Spring ,SpringMVC ,mybstis 的简称,mybatis的作用作为一个连接数据库的框架,可以很好配置连接好数据库, 有mybatis,我们对数据库增删改查的操作更为简便了。SSM框架是目前网站开发中比较常用和比较流行的框架,其中

ssm框架有六个层次controller ,dao层,model层,service层,mapping层,serviceImp层,我们的工程相关的截图如下;

技术分享

 

相关的六个层次的截图如下其中,mybatis 用来连接数据库,有mybatis,我们对数据库增删改查的操作更为简便了。SSM框架,我们用MAVEN工具对他们进行管理,maven 工具的主要作用就是为我们的工程自动配置好我们所需的架包,是通过POM.xml 文件进行依懒管理的。pom.xml的代码如下,配置了相关的依赖的管理;

其中pom.xml 配置文件的代码如下

<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   连接你的数据库的配置,还有一些作用自己理解。

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 我们现在来看看我们的登陆页面 ,我们现在使用[email protected]的账号进行登陆

 

技术分享

3 登陆进去的页面如下,进入到顾客的账号就可以对自己的信息进行相应的添加修改,浏览查看车辆的信息以及进行预订车辆的相关操作,都可以进行。

 

 

 

 

技术分享

4 比如我们对自己的信息进行修改和添加

技术分享

 

6 可以看见数据库的数据已经更新了

 技术分享

 

 

7我们在看看修改密码的功能 将密码修改为123456

技术分享

8 数据库密码已经更新了

技术分享

 

9 查看汽车的信息

技术分享

 

 

 

10 点击查看详情连接可以进入汽车的详情页

 

 

 

技术分享

 

 

11 相关的汽车详情页 现在还没有完全做好,到时候这个页面将提供汽车的详细的信息和相关的图片展示 以及汽车的预定页都将在这个页面实现

 

12  再说说另外一个在本系统权限的 最大的管理员的页面

技术分享

13 管理并没有注册的功能,他只有注册的功能,管理员的数据是直接操作数据库后台直接插进去,系统只是提供一个登陆的功能给他而已。意思是并不是每个人都可以注册成为系统的管理员

管理员可以对汽车管理和相关的职工的信息进行修改添加的增删改查的操作

技术分享

最后的吧,相关的页面展示到答辩再一一进行回答,相关的工作拖得有点晚,才导致这篇博客拖得这么晚,不过我想既然决定写好,就要将它写的比较好,起码对的起老师花费宝贵的时间来为我们进行审阅

五:团队相关的心得体会

    通过了这个汽车项目的锻炼,我们大家都一致的认为在软件的开发的过程中,团队协作以及精诚合作真的很重要,一个人的力量是非常有限的,但是团队团结起来的力量是强大的。团队合作是我们开发一个项目的不二之选。

其次,开发的过程我们遇到很多的困难,我们通过相互学习以及利用身边的书籍网上丰富的资源,解决掉项目不少的问题,通过我们同学之间的交流,思路的不同可以让我们收获颇多。善于学习别人的长处和利用身边的网上的资源,对于我们提高我们的学习能力以及我们自身的技术真的有很大的帮助。其次,开发项目要选择合适框架以及好的良好的码云等相关辅助相关的工具。对于我们开发的速度有很好的促进的作用,总而言之,我们团队需要通过这个汽车的租赁的项目,来自学吃透SSM框架的相关的内容,这应该就是我们做这个项目的最大的收获,最后的,加强我们团队整体的前端的页面的美化,虽然说自己做的页面自己都不想看,更何况是用户尼,所以学习的道路永远都是在路上,并没有所谓的终点。

 

                                                                                                                                                                                                                                                           谢谢各位花费宝贵的时间欣赏完本文,谢谢!

 

以上是关于汽车租赁管理开发流程的博客的主要内容,如果未能解决你的问题,请参考以下文章

汽车汽配行业SRM供应商管理系统数字化管理供应商,改进采购管理流程

芯原芯片设计流程获得ISO 26262汽车功能安全管理体系认证

当BPM业务流程管理遇上制造业

Sublime Text自定制代码片段(Code Snippets)

Android 逆向整体加固脱壳 ( DEX 优化流程分析 | DexPrepare.cpp 中 dvmOptimizeDexFile() 方法分析 | /bin/dexopt 源码分析 )(代码片段

汽车汽配行业经销商协同系统:实现汽配经销商销售管理全流程数字化