在开始开发一个系统之前,首先需要做的就是根据需求分析设计系统的实体对象以及对应的数据库表结构,这是开发的基础。
根据前面的需求分析设计的功能模块,实体对象可以分为5个模块,分别是系统模块(system)、基础模块(base)、采购模块(purchase)、销售模块(sale)、库存模块(stock)。下面是实体清单:
有了清单之后,利用PowerDesigner进行数据库物理模型设计。由于拥有对数据库的完全控制权,所以不对表设置约束,所有的约束在程序代码中进行控制。下面列出各个实体的属性即对应的表,具体可参考《数据库物理模型.pdm》。物理模型设计完成后,创建名为gpss的数据库,然后创建各个表。
数据库模型:
需求分析做完了,技术没问题,底层架构也设计好了,数据库设计好了,前面的所有准备工作做完了,下面就要进行燃气管进销存系统的编码实现了。首先要做的工作就是创建工程,项目名拟为gpss,即燃气管进销存(Gas Purchase Sale Stock)的缩写,工程名则为lyyzoo-gpss。
在IDEA中创建lyyzoo-gpss的maven工程,继承lyyzoo。同时,在lyyzoo-gpss下创建两个子模块,分别为lyyzoo-gpss-base和lyyzoo-gpss-web,base模块包含了系统的dao、entity、service等层次,主要为java文件;web则包含了controller层、jsp、js等web相关资源文件。
lyyzoo-gpss目录结构:
lyyzoo-gpss > pom.xml:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
4 <parent>
5 <groupId>com.lyyzoo</groupId>
6 <artifactId>lyyzoo</artifactId>
7 <version>1.0-SNAPSHOT</version>
8 </parent>
9 <groupId>com.lyyzoo.gpss</groupId>
10 <artifactId>lyyzoo-gpss</artifactId>
11 <name>lyyzoo :: gpss</name>
12 <packaging>pom</packaging>
13
14 <modules>
15 <module>lyyzoo-gpss-base</module>
16 <module>lyyzoo-gpss-web</module>
17 </modules>
18
19 <profiles>
20 <!-- 开发环境 -->
21 <profile>
22 <id>dev</id>
23 <activation>
24 <property>
25 <name>env</name>
26 <value>dev</value>
27 </property>
28 </activation>
29 </profile>
30 <!-- 线上环境 -->
31 <profile>
32 <id>online</id>
33 <activation>
34 <property>
35 <name>env</name>
36 <value>online</value>
37 </property>
38 </activation>
39 </profile>
40 </profiles>
41 <build>
42 <plugins>
43 <plugin>
44 <groupId>com.juvenxu.portable-config-maven-plugin</groupId>
45 <artifactId>portable-config-maven-plugin</artifactId>
46 <version>1.1.5</version>
47 <executions>
48 <execution>
49 <goals>
50 <goal>replace-package</goal>
51 </goals>
52 </execution>
53 </executions>
54 <configuration>
55 <portableConfig>src/main/resources/portable/config-${env}.xml</portableConfig>
56 </configuration>
57 </plugin>
58 </plugins>
59 </build>
60
61 </project>
lyyzoo-gpss-base主要是dao层、service层、model层的集成,所以需要依赖于底层lyyzoo-starter-jpa、lyyzoo-starter-web。
lyyzoo-gpss-base > pom.xml:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
4 <parent>
5 <groupId>com.lyyzoo.gpss</groupId>
6 <artifactId>lyyzoo-gpss</artifactId>
7 <version>1.0-SNAPSHOT</version>
8 </parent>
9 <artifactId>lyyzoo-gpss-base</artifactId>
10 <name>lyyzoo :: gpss :: base</name>
11 <packaging>jar</packaging>
12
13 <dependencies>
14 <dependency>
15 <groupId>com.lyyzoo</groupId>
16 <artifactId>lyyzoo-starter-jpa</artifactId>
17 </dependency>
18 <dependency>
19 <groupId>com.lyyzoo</groupId>
20 <artifactId>lyyzoo-starter-web</artifactId>
21 </dependency>
22 </dependencies>
23
24 </project>
lyyzoo-gpss-web是web相关,是controller层所在。依赖于lyyzoo-gpss-base、lyyzoo-starter-base等。
lyyzoo-gpss-web > pom.xml:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 <modelVersion>4.0.0</modelVersion>
4 <parent>
5 <groupId>com.lyyzoo.gpss</groupId>
6 <artifactId>lyyzoo-gpss</artifactId>
7 <version>1.0-SNAPSHOT</version>
8 </parent>
9 <artifactId>lyyzoo-gpss-web</artifactId>
10 <name>lyyzoo :: gpss :: web</name>
11 <packaging>war</packaging>
12
13 <dependencies>
14 <dependency>
15 <groupId>com.lyyzoo.gpss</groupId>
16 <artifactId>lyyzoo-gpss-base</artifactId>
17 <version>${project.version}</version>
18 </dependency>
19 <dependency>
20 <groupId>com.lyyzoo</groupId>
21 <artifactId>lyyzoo-starter-base</artifactId>
22 </dependency>
23 <dependency>
24 <groupId>com.lyyzoo</groupId>
25 <artifactId>lyyzoo-starter-jpa</artifactId>
26 </dependency>
27 <dependency>
28 <groupId>com.lyyzoo</groupId>
29 <artifactId>lyyzoo-starter-web</artifactId>
30 </dependency>
31 <dependency>
32 <groupId>com.lyyzoo</groupId>
33 <artifactId>lyyzoo-starter-test</artifactId>
34 </dependency>
35
36
37 </dependencies>
38
39
40 <build>
41 <finalName>gpss</finalName>
42 <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
43 </build>
44
45 </project>
工程建好后,首要要做的就是系统的配置工作了,如web.xml,这应该算是web项目的起点了。进入lyyzoo-gpss-web/src/main/webapp/WEB-INF/web.xml,进行web的配置,主要的一些配置有加载系统的配置文件、Spring、字符过滤器、SpringMVC等配置。
一些基础的配置如下:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6 version="3.0">
7
8 <display-name>lyyzoo :: gpss</display-name>
9
10 <!-- 加载配置文件 -->
11 <context-param>
12 <param-name>contextConfigLocation</param-name>
13 <param-value>classpath*:/spring/spring-base*.xml</param-value>
14 </context-param>
15
16 <!-- Spring -->
17 <listener>
18 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
19 </listener>
20
21 <!-- 编码过滤器 -->
22 <filter>
23 <filter-name>encodingFilter</filter-name>
24 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
25 <init-param>
26 <param-name>encoding</param-name>
27 <param-value>UTF-8</param-value>
28 </init-param>
29 <init-param>
30 <param-name>forceEncoding</param-name>
31 <param-value>true</param-value>
32 </init-param>
33 </filter>
34 <filter-mapping>
35 <filter-name>encodingFilter</filter-name>
36 <url-pattern>/*</url-pattern>
37 </filter-mapping>
38
39 <!-- 访问控制 -->
40 <filter>
41 <filter-name>VisitFilter</filter-name>
42 <filter-class>com.lyyzoo.gpss.filter.VisitFilter</filter-class>
43 </filter>
44 <filter-mapping>
45 <filter-name>VisitFilter</filter-name>
46 <url-pattern>/admin/*</url-pattern>
47 </filter-mapping>
48
49 <!-- Spring MVC -->
50 <servlet>
51 <servlet-name>SpringMVC</servlet-name>
52 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
53 <init-param>
54 <param-name>contextConfigLocation</param-name>
55 <param-value>classpath*:/spring/spring-web*.xml</param-value>
56 </init-param>
57 <load-on-startup>1</load-on-startup>
58 </servlet>
59 <servlet-mapping>
60 <servlet-name>SpringMVC</servlet-name>
61 <url-pattern>/</url-pattern>
62 </servlet-mapping>
63
64 <!-- 错误页面 -->
65 <error-page>
66 <error-code>404</error-code>
67 <location>/error/404</location>
68 </error-page>
69 <error-page>
70 <error-code>500</error-code>
71 <location>/error/500</location>
72 </error-page>
73 <error-page>
74 <exception-type>java.lang.Throwable</exception-type>
75 <location>/error/500</location>
76 </error-page>
77
78 <!-- 首页 -->
79 <welcome-file-list>
80 <welcome-file>/</welcome-file>
81 </welcome-file-list>
82
83 </web-app>
接着,配置系统将会用到的一些属性,如JDBC驱动、数据库用户名和密码等。在lyyzoo-gpss-web/src/main/resources/config下,创建config.properties配置文件,这个配置文件中的属性将会被底层spring配置的文件所引用。
比如JDBC的属性:
1 ####################################
2 # DATABASE
3 ####################################
4 # local_db
5 jdbc.driver=net.sf.log4jdbc.DriverSpy
6 jdbc.url=jdbc:log4jdbc:mysql://localhost:3306/gpss?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false
7 jdbc.username=root
8 jdbc.password=root
9
10 # 初始化连接
11 c3p0.initialPoolSize=5
12 # 连接池保留最小连接数
13 c3p0.minPoolSize=5
14 # 连接池保留最大连接数
15 c3p0.maxPoolSize=15
16 # 最大空闲时间
17 c3p0.maxIdleTime=600
18
19 #hibernate
20 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
21 hibernate.show.sql=false
22 hibernate.hbm2ddl.auto=update
但是上面的配置只是本机的一个开发环境,如果我将项目发布到生产环境,那就至少需要重新修改数据库地址、用户名和密码。这样是比较麻烦的,所以,在lyyzoo-gpss-web/src/main/portable下创建两个xml文件,分别为开发环境和生产环境的:config-dev.xml和config-online.xml。
config-online.xml:
1 <?xml version="1.0" encoding="utf-8" ?>
2
3 <portable-config>
4 <config-file path="WEB-INF/classes/config/config.properties">
5
6 <!-- JDBC -->
7 <replace key="jdbc.driver"><![CDATA[com.mysql.jdbc.Driver]]></replace>
8 <replace key="jdbc.url"><![CDATA[jdbc:mysql://192.168.1.91:30112/fff2f025c2b04?useUnicode=true&characterEncoding=utf-8]]></replace>
9 <replace key="jdbc.username">a6564a1169d94</replace>
10 <replace key="jdbc.password">d3e6d1aea5e04</replace>
11
12 <!-- hibernate -->
13 <replace key="hibernate.show.sql">false</replace>
14 <replace key="hibernate.hbm2ddl.auto">none</replace>
15
16 <!-- debug -->
17 <replace key="app.debug">false</replace>
18 <replace key="app.env">online</replace>
19 <replace key="logback.level">INFO</replace>
20 <replace key="jdbc.resultsettable">ERROR</replace>
21
22
23 </config-file>
24 </portable-config>
然后配置一个“不同环境打包”的maven插件——“portable-config-maven-plugin”,通过该插件,就可以在打包的时候加上需要打包的环境,例如指定online环境,在打包时就会将config-online.xml中的属性替换到config.properties里,这样一来就不必我们手动去替换了。配置好之后,我们在打包时可以使用命令[mvn clean package –Denv=online]打包线上环境的war包。
maven环境配置,在lyyzoo-gpss > pom.xml中配置两个环境:
1 <profiles>
2 <!-- 开发环境 -->
3 <profile>
4 <id>dev</id>
5 <activation>
6 <property>
7 <name>env</name>
8 <value>dev</value>
9 </property>
10 </activation>
11 </profile>
12 <!-- 线上环境 -->
13 <profile>
14 <id>online</id>
15 <activation>
16 <property>
17 <name>env</name>
18 <value>online</value>
19 </property>
20 </activation>
21 </profile>
22 </profiles>
不同环境打包插件(portable-config-maven-plugin)的配置:
1 <build>
2 <plugins>
3 <plugin>
4 <groupId>com.juvenxu.portable-config-maven-plugin</groupId>
5 <artifactId>portable-config-maven-plugin</artifactId>
6 <version>1.1.5</version>
7 <executions>
8 <execution>
9 <goals>
10 <goal>replace-package</goal>
11 </goals>
12 </execution>
13 </executions>
14 <configuration>
15 <portableConfig>src/main/resources/portable/config-${env}.xml</portableConfig>
16 </configuration>
17 </plugin>
18 </plugins>
19 </build>
工程建好后,创建包的结构。按照一般的分层方式,分为dao层、entity层、service层,同时,每层下按模块划分为system、base、purchase、sale、stock。然后在entity下根据表设计创建实体类。
lyyzoo-gpss-base 目录结构:
然后是lyyzoo-gpss-web模块,该模块主要是controller层,以及静态资源文件、jsp文件等。com.lyyzoo.gpss.web作为controller层的包,同样,在web下按系统模块划分。
lyyzoo-gpss-web 目录结构:
lyyzoo-gpss-web/src/main/webapp/static作为静态文件的根目录,static/lib目录作为三方类库的根目录,如ExtJs、jQuery、其它的插件等。static/css是系统css文件的根目录;static/img是图片的根目录;static/js是系统js文件根目录,/js下同样按模块划分。
静态资源文件目录结构:
jsp文件不能直接让用户访问,需要放到/WEB-INF下,与配置的spring视图解析器相对应,所有的jsp文件放到/WEB-INF/view目录下,view目录下按模块划分,index.jsp是系统的登录页面。/WEB-INF/layout/目录下,将jsp中需要引入的一些资源等做了整合,如ExtJs的文件、meta描述信息、taglib等,整合后,jsp中如果需要引入整合jsp即可,可减少很多重复的工作。
taglib.jsp中引入了标签和设置了资源的路径:
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2
3 <%-- 引入标签 --%>
4 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
5 <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
6 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
7 <%@taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
8
9 <%-- 资源路径 --%>
10 <c:set var="CTX" value="${pageContext.request.contextPath}" />
11 <c:set var="STATIC_CTX_URL" value="${CTX}/static" />
12 <c:set var="LIB" value="${STATIC_CTX_URL}/lib" />
13 <c:set var="JS" value="${STATIC_CTX_URL}/js"/>
14 <c:set var="CSS" value="${STATIC_CTX_URL}/css"/>
15 <c:set var="IMG" value="${STATIC_CTX_URL}/img"/>
meta.jsp中主要设置了一些meta描述信息和ICO图标:
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <%@ include file="/WEB-INF/layout/taglib.jsp" %>
3
4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=9,chrome=1">
6
7 <meta name="description" content="">
8 <meta name="author" content="">
9 <meta name="renderer" content="webkit">
10 <%-- 图标 --%>
11 <link type="image/x-icon" href="${IMG}/favicon.ico" rel="icon">
extjs-neptune.jsp则引入了ExtJs相关的css和js文件,以及jQuery等:
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <%@ include file="/WEB-INF/layout/taglib.jsp" %>
3
4 <link rel="stylesheet" type="text/css" href="${LIB}/ext/4.2.2/theme/ext-theme-neptune/ext-theme-neptune-all.css"/>
5 <link rel="stylesheet" type="text/css" href="${LIB}/ext/4.2.2/icons/icon.css"/>
6
7 <script type="text/javascript" src="${LIB}/ext/4.2.2/ext-all.js"></script>
8 <script type="text/javascript" src="${LIB}/ext/4.2.2/locale/ext-lang-zh_CN.js"></script>
9 <script type="text/javascript" src="${LIB}/jquery/2.1.1/jquery.js"></script>
10 <script type="text/javascript" src="${JS}/Global.js"></script>
11
12 <script type="text/javascript">
13 window.CTX = "${CTX}";
14 window.STATIC_CTX_URL = "${STATIC_CTX_URL}";
15 window.LIB = "${LIB}";
16 window.JS = "${JS}";
17 window.CSS = "${CSS}";
18 window.IMG = "${IMG}";
19 </script>
WEB-INF目录结构:
首先创建一个BaseController,BaseController继承底层的BaseController,增加了HttpSession,以及获取当前登录用户的方法,这样其它的controller继承该BaseController后,就可以非常方便的获得当前session和登录用户了。
BaseController代码如下:
1 package com.lyyzoo.gpss.web;
2
3 import com.lyyzoo.gpss.entity.system.User;
4 import org.springframework.beans.factory.annotation.Autowired;
5
6 import javax.servlet.http.HttpSession;
7
8 /**
9 *
10 * <p>
11 *
12 * @author bojiangzhou
13 * @date 2017-04-02
14 */
15 public class BaseController extends com.lyyzoo.web.BaseController {
16
17 @Autowired
18 protected HttpSession session;
19
20 public User getCurrentUser(){
21 return (User) session.getAttribute("currentUser");
22 }
23
24 public Long getCurrentUserId(){
25 return getCurrentUser().getId();
26 }
27
28 public String getCurrentUserAccount(){
29 return getCurrentUser().getAccount();
30 }
31
32 }
创建HomeController作为登录和主页的处理器。主要包含的方法有访问登录页面,访问登录后的主页,以及登录处理等。Controller需要加上@Controller标注该类为controller,使用@RequestMapping()支持访问rest形式的地址访问。HomeController中注入UserService,用于处理用户登录相关的业务。
用户进入登录界面,jsp页面以<img src=” ${CTX}/vcode”>的形式请求验证码,验证码使用工具类生成,以流的形式输出,生成的验证码保存到session中。用户输入登录账号、密码和验证码登录系统。首先前台会检测输入是否为空等,传到后台,从session中取出验证码判断验证码是否正确,不正确则刷新验证码并且需要用户重新输入验证码。验证码通过后,使用登录账号和密码查找数据库,如果有,则将该用户保存到session中,跳转到管理页面,登录成功。否则提示用户名或密码错误。
HomeController代码如下:
1 package com.lyyzoo.gpss.web;
2
3 import com.lyyzoo.gpss.entity.system.User;
4 import com.lyyzoo.gpss.service.system.UserService;
5 import com.lyyzoo.gpss.util.VCodeGenerator;
6 import com.lyyzoo.util.Cryptos;
7 import com.lyyzoo.util.Strings;
8 import org.springframework.beans.BeanUtils;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Controller;
11 import org.springframework.web.bind.annotation.PathVariable;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RequestMethod;
14
15 import javax.imageio.ImageIO;
16 import javax.servlet.http.HttpServletResponse;
17 import javax.servlet.http.HttpSession;
18 import java.awt.image.BufferedImage;
19 import java.io.IOException;
20
21 /**
22 * <p>
23 *
24 * @author bojiangzhou
25 * @date 2017-03-29
26 */
27 @Controller
28 @RequestMapping("")
29 public class HomeController extends BaseController {
30
31 @Autowired
32 private UserService userService;
33
34 /**
35 * 到首页/登录页面
36 */
37 @RequestMapping(value = {"", "/", "/index", "/login"})
38 public String index(){
39 return "/index";
40 }
41
42 /**
43 * 管理员主页
44 */
45 @RequestMapping("/admin/home")
46 public String toHome(){
47 return "/home/home";
48 }
49
50 /**
51 * 登录
52 */
53 @RequestMapping(value = "/login", method = RequestMethod.POST)
54 public String login(String account, String password, String vcode, HttpSession session){
55 String redirect = REDIRECT("/login");
56 //基本验证
57 if(Strings.isNullOrEmpty(account)){
58 session.setAttribute("errorMsg", "账号必须填写!");
59 return redirect;
60 }
61 if(Strings.isNullOrEmpty(password)){
62 session.setAttribute("errorMsg", "密码必须填写!");
63 return redirect;
64 }
65 if(Strings.isNullOrEmpty(vcode)){
66 session.setAttribute("errorMsg", "验证码必须填写!");
67 return redirect;
68 }
69 //验证码
70 String sessionVcode = (String) session.getAttribute("vcode");
71 if(!vcode.equalsIgnoreCase(sessionVcode)){
72 session.setAttribute("errorMsg", "验证码错误!");
73 return redirect;
74 }
75 //验证用户名和密码
76 password = Cryptos.encryptMd5(password);
77 User loginUser = userService.login(account, password);
78 if(loginUser == null){
79 session.setAttribute("errorMsg", "账号或密码错误!");
80 return redirect;
81 }
82 if(loginUser.getIsLocked() == User.IsLocked.YES){
83 session.setAttribute("errorMsg", "账号已锁定,不能登录!");
84 return redirect;
85 }
86
87 //保存到session的时候清除密码
88 User currentUser = new User();
89 BeanUtils.copyProperties(loginUser, currentUser);
90 currentUser.setPassword(null);
91
92 //登录成功
93 session.setAttribute("currentUser", currentUser);
94
95 return REDIRECT("/admin/home");
96 }
97
98 /**
99 * 获取验证码
100 */
101 @RequestMapping("/vcode")
102 public void getVCode(HttpSession session, HttpServletResponse response) throws IOException {
103 //创建验证码生成器对象
104 VCodeGenerator vcGenerator = new VCodeGenerator();
105 //生成验证码
106 String vcode = vcGenerator.generatorVCode();
107 //将验证码保存在session域中,以便判断验证码是否正确
108 session.setAttribute("vcode", vcode);
109 //生成验证码图片
110 BufferedImage vImg = vcGenerator.generatorRotateVCodeImage(vcode, true);
111 //输出图像
112 ImageIO.write(vImg, "gif", response.getOutputStream());
113 }
114
115 /**
116 * 退出系统
117 */
118 @RequestMapping("/logoff")
119 public String logoff(HttpSession session){
120 session.invalidate();
121 return REDIRECT("/");
122 }
123
124 @RequestMapping("/function")
125 public String function(){
126 return "/home/function";
127 }
128
129 @RequestMapping("/welcome")
130 public String welcome(){
131 return "/home/welcome";
132 }
133
134 /**
135 * 错误页面
136 * @param code
137 * @return
138 */
139 @RequestMapping("/error/{code}")
140 public String error(@PathVariable String code) {
141 return "/error/" + code;
142 }
143
144
145
146 }
UserService中根据用户名和密码获取用户:
1 package com.lyyzoo.gpss.service.system;
2
3 @Service
4 public class UserService extends BaseService<User> {
5 @Autowired
6 private UserDao userDao;
7 /**
8 * 获取登录用户
9 */
10 public User login(String account, String password){
11 Map<String, Object> filter = new HashMap<>();
12 filter.put("account", account);
13 filter.put("password", password);
14 filter.put("state", Applications.Flag.YES);
15
16 User loginUser = get(filter);
17 return loginUser;
18 }
19 }
系统开发完成后,首先需要在本地整体测试,从登录开始,每个模块,每个功能,每个流程具体的去测试。
首先测试如果未登录,用户是不能访问管理页面的,直接在地址栏输入访问地址看是否跳转到登录页面。然后至少测试各个角色相关的账号登录是否正常,登录后,每个角色拥有的菜单是否显示正常。
其它模块的测试,使用各个角色对应的账号,登录系统,进行相应功能的测试。如管理员进入系统录入基础数据,商品信息、仓库信息等。采购管理员录入供应商信息,录入采购订单,提交审核。销售管理员录入客户信息,录入销售订单,提交审核。库存管理员审核采购订单,审核通过,则库存增加;审核销售订单,审核通过,则库存减少。查看库存信息,相应的操作之后,库存量是否正确。测试结果可查看系统测试截图。
系统容错性测试,主要是测试输入一些错误的数据类型以及超出范围的数值测试系统在异常条件下的行为。系统在这方面做得比较好,如果用户输入了一些非法的数据,会立即提醒用户输入正确的数据。首先会在前台判断用户输入的数据的合法性、是否必须输入等,数据传到后台后,还会在代码里判断一次数据是否正确,才会保存到数据库。而系统使用的Jdbc也能在一定程度上防止SQL注入等问题。如果系统发生一些无法预测的异常,也会以友好的界面提示用户,以便技术员及时维护系统。
总体来说,整个的测试过程比较顺利,也存在一些小问题,就立即修复了。功能全部实现了,该系统能满足一个基本的进销存流程,以后也还可以扩展。
我这里使用磨泊云来部署项目,磨泊云使用简单且在一定限度内免费,部署测试比较合适。首先在磨泊云上创建名为gpss的Java应用,接着创建mysql服务,并将其绑定到该java应用,复制数据库连接到配置文件中。导出本地的gpss数据库,导入到创建的mysql应用里。然后在IDEA中使用mvn clean package –Denv=online命令打包线上环境的war包,将war包发布到磨泊云上。启动项目,然后访问,测试,一些都正常。可访问域名http://gpss.butterfly.mopaasapp.com/查看,由于没处理好ext的兼容性问题,建议使用谷歌浏览器查看。后面再学学如何部署到像阿里云等云上。
(完)