一: 项目概述和环境搭建
(1) 项目概述
1.1. 项目介绍(项目背景)
? 传智健康管理系统是一款应用于健康管理机构(慈铭、爱康国宾)的业务系统,实现健康管理机构工作内容可视化、会员管理专业化、健康评估数字化、健康干预流程化、知识库集成化,从而提高健康管理师的工作效率,加强与会员间的互动,增强管理者对健康管理机构运营情况的了解。
1.2. 项目需求分析
1:传智健康项目的业务需求
2:课程中需完成的业务需求
【路径】
1:传智健康管理系统是一款应用于健康管理机构的业务系统
2:系统分为传智健康后台管理系统和移动端应用两部分
3:后台系统和移动端应用都会通过Dubbo调用服务层发布的服务来完成具体的操作。本项目属于典型的SOA架构形式
【讲解】
传智健康项目架构图
? 传智健康管理系统是一款应用于健康管理机构的业务系统,实现健康管理机构工作内容可视化、患者管理专业化、健康评估数字化、健康干预流程化、知识库集成化,从而提高健康管理师的工作效率,加强与患者间的互动,增强管理者对健康管理机构运营情况的了解。
? 系统分为传智健康后台管理系统和移动端应用两部分。其中后台系统提供给健康管理机构内部人员(包括系统管理员、健康管理师等)使用,微信端应用提供给健康管理机构的用户(体检用户)使用。
本项目功能架构图:
? 通过上面的功能架构图可以看到,传智健康后台管理系统有会员管理、预约管理、健康评估、健康干预等功能。移动端有会员管理、体检预约、体检报告等功能。后台系统和移动端应用都会通过Dubbo调用服务层发布的服务来完成具体的操作。本项目属于典型的SOA架构形式。
? 本章节完成的功能开发是预约管理功能,包括检查项管理(身高,体重)、检查组管理(外科)、体检套餐管理(公司健康体检)、预约设置等(参见产品原型)。预约管理属于系统的基础功能,主要就是管理一些体检的基础数据。
【需求分析小结】
? 系统分为传智健康后台管理系统和移动端应用两部分。其中后台系统提供给健康管理机构内部人员(包括系统管理员、健康管理师等)使用,微信端应用提供给健康管理机构的用户(体检用户)使用。
? 传智健康后台管理系统有会员管理、预约管理、健康评估、健康干预等功能。移动端有会员管理、体检预约、体检报告等功能
? 本项目属于典型的SOA架构形式,服务调用使用Dubbo,注册中心使用zookeeper
1.2. 原型展示
略
1.3. 技术架构
1.4. 功能架构(SOA架构)
1.5. 软件开发流程 【次重点-能说出来】
软件开发一般会经历如下几个阶段,整个过程是顺序展开,所以通常称为瀑布模型。
还有增量模型:递增方式进行开发。
敏捷开发模式
【小结】
1:掌握项目的功能介绍
2:项目中的2套系统
PC端管理系统(体检机构人员),移动端系统(客户(互联网用户),即体检人员)
3:技术架构
- 掌握项目开发技术。。 ssm, poi, freemarker, pagehelper, 报表echars, jsperReport, security, redis, 云短信…
4:功能架构
5:软件开发流程
3. 环境搭建 【重点】
【目标】
使用maven搭建系统环境
【路径】
0:项目结构
1:父工程health_parent
2:子工程health_common(工具类)
3:子工程health_pojo(实体类)
4:子工程health_dao(Dao类)
5:子工程health_interface(接口方法,用在dubbo数据调用)
6:子工程health_service(Service类)
7:子工程health_web(表现层)
8:测试
其中web是war项目,service是war项目,实现服务间的调用
3.1. 项目结构
本项目采用maven分模块开发方式,即对整个项目拆分为几个maven工程,每个maven工程存放特定的一类代码,具体如下: 各模块职责定位:
health_parent:父工程,打包方式为pom,统一锁定依赖的版本,同时聚合其他子模块便于统一执行maven命令
health_common:通用模块,打包方式为jar,存放项目中使用到的一些工具类和常量类
health_pojo:打包方式为jar,存放实体类和返回结果类等
health_dao:持久层模块,打包方式为jar,存放Dao接口和Mapper映射文件等
health_interface:打包方式为jar,存放服务接口
health_service:Dubbo服务模块,打包方式为war,存放服务实现类,作为服务提供方,需要部署到tomcat运行
health_web:打包方式为war,作为Dubbo服务消费方,存放Controller、HTML页面、js、css、spring配置文件等,需要部署到tomcat运行
3.2. maven项目搭建
通过前面的项目功能架构图可以知道本项目分为传智健康管理后台和传智健康管理前台(微信端),本小节我们先搭建管理后台项目
3.2.1. health_parent
【路径】
1:创建工程
2:导入坐标
【讲解】
1:创建health_parent,父工程,打包方式为pom,用于统一管理依赖版本
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itheima</groupId>
<artifactId>health_parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<junit.version>4.12</junit.version>
<spring.version>5.0.5.RELEASE</spring.version>
<pagehelper.version>4.1.4</pagehelper.version>
<servlet-api.version>2.5</servlet-api.version>
<dubbo.version>2.6.0</dubbo.version>
<zookeeper.version>3.4.7</zookeeper.version>
<zkclient.version>0.1</zkclient.version>
<mybatis.version>3.4.5</mybatis.version>
<mybatis.spring.version>1.3.1</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.32</mysql.version>
<druid.version>1.0.9</druid.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<spring.security.version>5.0.5.RELEASE</spring.security.version>
<poi.version>3.14</poi.version>
<jedis.version>2.9.0</jedis.version>
<quartz.version>2.2.1</quartz.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</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-webmvc</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-aspects</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>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
3.2.2. health_common
【路径】
1:创建工程
2:导入坐标(继承父工程、导入所有jar包)
【讲解】
1:创建health_common,子工程,打包方式为jar,存放通用组件,例如工具类等
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_common</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
</dependencies>
</project>
3.2.3. health_pojo
【路径】
1:创建工程
2:导入坐标(继承父工程、依赖health_common)
“实体entity、JavaBean、Model、POJO、domain的区别”
https://blog.csdn.net/u011665991/article/details/81201499
“PO、VO、BO、DTO、POJO、DAO”
https://blog.csdn.net/keepd/article/details/78272042
【讲解】
1:创建health_pojo,子工程,打包方式为jar,存放POJO实体类
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_pojo</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3.2.4. health_dao
【路径】
1:创建工程
2:导入坐标(继承父工程、依赖health_pojo)
3:log4j.properties
4:sqlMapConfig.xml(mybatis的配置文件)
5:applicationContext-dao.xml(spring整合mybatis)
6:接口类(后续添加实体后,再创建)
7:接口类对应的映射文件(后续添加实体后,再创建)
【讲解】
1:创建health_dao,子工程,打包方式为jar,存放Dao接口和Mybatis映射文件
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_dao</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3:log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, stdout
4:sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>
【学习】:分页插件网址:https://pagehelper.github.io/
5:applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource"
class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="username" value="root" />
<property name="password" value="root" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/health89" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml" />
<property name="typeAliasesPackage" value="com.itheima.health.pojo"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.itheima.health.dao" />
</bean>
</beans>
使用分页插件另外的配置方式,不需要sqlMapConfig: 如果配置了sqlMapConfig就不需要下面的配置
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<props>
<prop key="dialect">mysql</prop>
</props>
</property>
</bean>
</array>
</property>
<property name="typeAliasesPackage" value="com.itheima.health.pojo"></property>
</bean>
3.2.5. health_interface
【路径】
1:创建工程
2:导入坐标(继承父工程,依赖health_pojo)
【讲解】
1:创建health_interface,子工程,打包方式为jar,存放服务接口,用于dubbo在服务提供者和服务消费者中使用。
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_interface</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3.2.6. health_service
【路径】
1:创建工程
2:导入坐标(继承父工程、依赖health_interface、health_dao)(war包)
3:log4j.properties
4:applicationContext-tx.xml(spring的声明式事务处理)
5:applicationContext-service.xml(spring整合dubbo,服务提供者,导入dao配置)
6:web.xml(spring的监听器,当web容器启动的时候,自动加载spring容器)
【讲解】
1:创建health_service,子工程,打包方式为war,作为服务单独部署,存放服务类
2:pom.xml
需要设置war
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_service</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3:log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, stdout
4:applicationContext-tx.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<import resource="classpath:applicationContext-dao.xml"/>
</beans>
5:applicationContext-service.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="health_service"/>
<dubbo:protocol name="dubbo" port="20887"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:annotation package="com.itheima.health.service"/>
<import resource="classpath:applicationContext-tx.xml"/>
</beans>
6: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"
id="WebApp_ID" version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-service.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
3.2.7. health_web
【路径】
1:创建工程
2:导入坐标(继承父工程、依赖health_interface)
3:log4j.properties
4:springmvc.xml(spring整合dubbo2.6.0,服务消费者;springmvc的配置、上传组件)
5:web.xml(springmvc的核心控制器,当web容器启动的时候,自动加载springmvc.xml)
【讲解】
1:创建health_web,子工程,打包方式为war,单独部署,存放Controller
2:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3:log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=info, stdout
4:springmvc.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<property name="features">
<list>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<dubbo:application name="health_web" />
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:annotation package="com.itheima.health.controller" />
<dubbo:consumer timeout="600000" check="false"/>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600" />
<property name="maxInMemorySize" value="4096" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
</beans>
FastJsonHttpMessageConverter配置定义了 @ResponseBody 支持的返回类型, json对空键值的处理方式 和 统一的日期返回格式(格式:yyyy-MM-dd)
5: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"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
这里,我们使用*.do的方式,表示只拦截.do结尾的url。
搭建完成后如下:
3.2.8 注册中心配置
拷贝zookeeper-3.4.5.tar.gz
我们可以不发布到linux上,放置到window上也是可以的。可以放置到D盘sortware上,避免出现中文。
解压
第1步:创建data 文件夹
第2步:修改conf下的zoo_simple.cfg文件,改名为zoo.cfg
第3步:配置zoo.cfg
第4步:启动Zookeeper后,然后启动health_service和health_web
导入测试页面(第2天资源)
【小结】
0:项目结构
1:父工程health_parent
2:子工程health_common(工具类)
3:子工程health_pojo(实体类)
4:子工程health_dao(Dao类)
5:子工程health_interface(接口方法,用在dubbo数据调用)
6:子工程health_service(Service类, dubbo2.6.0)
7:子工程health_web(表现层 dubbo2.6.0)
8:测试
4. 完善基础环境搭建
【目标】
基础环境搭建
【路径】
1:导入项目所需模块数据表
? health_dao数据库配置
2:导入项目所需模块实体类
3:导入项目所需公共资源
【讲解】
4.1. 导入项目所需模块数据表 【导】
4.2. 导入项目所需模块实体类
将资料中提供的POJO实体类复制到health_pojo工程中。
4.3. 导入项目所需公共资源
项目开发过程中一般会提供一些公共资源,供多个模块或者系统来使用。
本章节我们导入的公共资源有:
(1)返回消息常量类MessageConstant.java,放到health_common工程中
package com.itheima.health.constant;
public interface MessageConstant {
static final String DELETE_CHECKITEM_FAIL = "删除检查项失败";
static final String DELETE_CHECKITEM_SUCCESS = "删除检查项成功";
static final String ADD_CHECKITEM_SUCCESS = "新增检查项成功";
static final String ADD_CHECKITEM_FAIL = "新增检查项失败";
static final String EDIT_CHECKITEM_FAIL = "编辑检查项失败";
static final String EDIT_CHECKITEM_SUCCESS = "编辑检查项成功";
static final String QUERY_CHECKITEM_SUCCESS = "查询检查项成功";
static final String QUERY_CHECKITEM_FAIL = "查询检查项失败";
static final String UPLOAD_SUCCESS = "上传成功";
static final String ADD_CHECKGROUP_FAIL = "新增检查组失败";
static final String ADD_CHECKGROUP_SUCCESS = "新增检查组成功";
static final String DELETE_CHECKGROUP_FAIL = "删除检查组失败";
static final String DELETE_CHECKGROUP_SUCCESS = "删除检查组成功";
static final String QUERY_CHECKGROUP_SUCCESS = "查询检查组成功";
static final String QUERY_CHECKGROUP_FAIL = "查询检查组失败";
static final String EDIT_CHECKGROUP_FAIL = "编辑检查组失败";
static final String EDIT_CHECKGROUP_SUCCESS = "编辑检查组成功";
static final String PIC_UPLOAD_SUCCESS = "图片上传成功";
static final String PIC_UPLOAD_FAIL = "图片上传失败";
static final String ADD_SETMEAL_FAIL = "新增套餐失败";
static final String ADD_SETMEAL_SUCCESS = "新增套餐成功";
static final String IMPORT_ORDERSETTING_FAIL = "批量导入预约设置数据失败";
static final String IMPORT_ORDERSETTING_SUCCESS = "批量导入预约设置数据成功";
static final String GET_ORDERSETTING_SUCCESS = "获取预约设置数据成功";
static final String GET_ORDERSETTING_FAIL = "获取预约设置数据失败";
static final String ORDERSETTING_SUCCESS = "预约设置成功";
static final String ORDERSETTING_FAIL = "预约设置失败";
static final String ADD_MEMBER_FAIL = "新增会员失败";
static final String ADD_MEMBER_SUCCESS = "新增会员成功";
static final String DELETE_MEMBER_FAIL = "删除会员失败";
static final String DELETE_MEMBER_SUCCESS = "删除会员成功";
static final String EDIT_MEMBER_FAIL = "编辑会员失败";
static final String EDIT_MEMBER_SUCCESS = "编辑会员成功";
static final String TELEPHONE_VALIDATECODE_NOTNULL = "手机号和验证码都不能为空";
static final String LOGIN_SUCCESS = "登录成功";
static final String VALIDATECODE_ERROR = "验证码输入错误";
static final String QUERY_ORDER_SUCCESS = "查询预约信息成功";
static final String QUERY_ORDER_FAIL = "查询预约信息失败";
static final String QUERY_SETMEALLIST_SUCCESS = "查询套餐列表数据成功";
static final String QUERY_SETMEALLIST_FAIL = "查询套餐列表数据失败";
static final String QUERY_SETMEAL_SUCCESS = "查询套餐数据成功";
static final String QUERY_SETMEAL_FAIL = "查询套餐数据失败";
static final String SEND_VALIDATECODE_FAIL = "验证码发送失败";
static final String SEND_VALIDATECODE_SUCCESS = "验证码发送成功";
static final String SELECTED_DATE_CANNOT_ORDER = "所选日期不能进行体检预约";
static final String ORDER_FULL = "预约已满";
static final String HAS_ORDERED = "已经完成预约,不能重复预约";
static final String ORDER_SUCCESS = "预约成功";
static final String GET_USERNAME_SUCCESS = "获取当前登录用户名称成功";
static final String GET_USERNAME_FAIL = "获取当前登录用户名称失败";
static final String GET_MENU_SUCCESS = "获取当前登录用户菜单成功";
static final String GET_MENU_FAIL = "获取当前登录用户菜单失败";
static final String GET_MEMBER_NUMBER_REPORT_SUCCESS = "获取会员统计数据成功";
static final String GET_MEMBER_NUMBER_REPORT_FAIL = "获取会员统计数据失败";
static final String GET_SETMEAL_COUNT_REPORT_SUCCESS = "获取套餐统计数据成功";
static final String GET_SETMEAL_COUNT_REPORT_FAIL = "获取套餐统计数据失败";
static final String GET_BUSINESS_REPORT_SUCCESS = "获取运营统计数据成功";
static final String GET_BUSINESS_REPORT_FAIL = "获取运营统计数据失败";
static final String GET_SETMEAL_LIST_SUCCESS = "查询套餐列表数据成功";
static final String GET_SETMEAL_LIST_FAIL = "查询套餐列表数据失败";
}
(2)返回结果Result和PageResult类,放到health_pojo工程中
【1】Result.java
处理响应结果集
package com.itheima.health.entity;
import java.io.Serializable;
public class Result implements Serializable{
private boolean flag;
private String message;
private Object data;
public Result(boolean flag, String message) {
super();
this.flag = flag;
this.message = message;
}
public Result(boolean flag, String message, Object data) {
this.flag = flag;
this.message = message;
this.data = data;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
【2】PageResult.java
处理分页列表结果集。
package com.itheima.health.entity;
import java.io.Serializable;
import java.util.List;
public class PageResult implements Serializable{
private Long total;
private List rows;
public PageResult(Long total, List rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
}
(3)封装查询条件的QueryPageBean类,放到health_pojo工程中
用于封装查询条件
package com.itheima.health.entity;
import java.io.Serializable;
public class QueryPageBean implements Serializable{
private Integer currentPage;
private Integer pageSize;
private String queryString;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public String getQueryString() {
return queryString;
}
public void setQueryString(String queryString) {
this.queryString = queryString;
}
}
(4)把资料中"07_公共资源\页面端静态资源"中的html、js、css、图片等静态资源,放到health_web工程中webapp目录下
注意:后续随着项目开发还会陆续导入其他一些公共资源。
【小结】
1:导入项目所需模块数据表 执行06_SQL脚本下脚本
2:导入项目所需模块实体类 注意包名要一致
其中CheckItem.java表示检查项(后续开发内容)。
3:导入项目所需公共资源
(1)MessageConstant.java:返回消息常量类
(2)Result.java:处理响应结果集 与前端开发约定好的数据类型
(3)PageResult.java:分页列表结果集。
(4)QueryPageBean.java:封装分页查询条件
(页面): 页面端静态资源 里的内容复制到health_web/webapp/目录下,找开目录来粘贴。
5. 查询检查项(不分页)
【目标】
1:查询所有检查项(elementUI+vuejs+axios)
2:熟悉查询功能中的响应数据
3:检查项查询功能实现
【路径】
- 进入页面,找到created的钩子方法,发送axios请求checkitem/findAll.do获取数据,获取的返回数据是一个Result(flag,message,data), 判断flag,如果成功为true, 绑定数据 data绑定到this.dataList。如果失败要提示
- CheckItemController处理checkitem/findAll.do。调用业务服务findAll返回list,包装到result,再返回给页面
- CheckItemService, CheckItemServiceImpl,提供findAll返回List
- CheckItemDao与映射文件 提供findAll返回List select * From t_checkitem
【讲解】
本项目所有分页功能都是基于ajax的异步请求来完成的,请求参数和后台响应数据格式都使用json数据格式。
后台响应数据包括Result对象(falg,message,data)。data可以存放List
响应数据的json格式为:
{flag:true,message:“查询检查项成功”,data:[{id:1,code:"",name:""},{id2,code:"",name:""}]}
5.1. 前台代码
5.1.1. 定义模型数据
因为使用vue开发,需要定义模型
5.1.2. 定义初始化方法
在页面中提供了findPage方法用于查询,为了能够在checkitem.html页面加载后直接可以展示数据,可以在VUE提供的钩子函数created中调用findPage方法
created() {
axios.get('/checkitem/findAll.do').then(res => {
var result = res.data;
if(result.flag){
this.dataList = result.data;
}else{
this.$message({
message: result.message,
type: "error"
})
}
})
}
5.2. 后台代码
5.2.1. Controller
创建CheckItemController中增加分页查询方法
package com.itheima.health.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.constant.MessageConstant;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {
@Reference
private CheckItemService checkItemService;
@GetMapping("/findAll")
public Result findAll(){
List<CheckItem> list = checkItemService.findAll();
return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
}
}
5.2.2. 服务接口
在health_interface中创建CheckItemService服务接口中扩展查询方法
package com.itheima.health.service;
import com.itheima.health.pojo.CheckItem;
import java.util.List;
public interface CheckItemService {
List<CheckItem> findAll();
}
5.2.3. 服务实现类
在health_service中创建CheckItemServiceImpl服务实现类中实现查询方法。
package com.itheima.health.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.CheckItemDao;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Service(interfaceClass = CheckItemService.class)
public class CheckItemServiceImpl implements CheckItemService {
@Autowired
private CheckItemDao checkItemDao;
@Override
public List<CheckItem> findAll() {
return checkItemDao.findAll();
}
}
5.2.4. Dao接口
在health_dao中创建CheckItemDao接口中扩展查询方法
package com.itheima.health.dao;
import com.itheima.health.pojo.CheckItem;
import java.util.List;
public interface CheckItemDao {
List<CheckItem> findAll();
}
5.2.5. Mapper映射文件
在health_dao的resources/com/itheima/health/dao下创建CheckItemDao.xml文件中增加SQL定义
<?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="com.itheima.health.dao.CheckItemDao">
<select id="findAll" resultType="checkitem">
select * from t_checkitem
</select>
</mapper>
【小结】
1:前台代码
(1)定义查询相关模型数据
(2)定义初始化方法created,查询所有
- 使用钩子函数,初始化数据 发送axios.get,获取返回的数据绑定到dataList
2:后台代码
(1)CheckItemController.java
(2)CheckItemService.java(服务接口)
(3)CheckItemServiceImpl.java(服务实现类)
(4)ckItemDao.java(Dao接口)
(5)CheckItemDao.xml(Mapper映射文件)
<!
<select id="findAll" resultType="checkitem">
select * from t_checkitem
</select>
套路:前端发送请求,controller接收,调用service, 调用dao, service返回结果给controller, controller包装成result返回给页面,页面接收result 判断失败提示,成功就绑定数据
6.2.1. Container 布局容器
用于布局的容器组件,方便快速搭建页面的基本结构:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ASuEwlJW-1632234936190)(./img/055.png)]
:外层容器。当子元素中包含 或 时,全部子元素会垂直上下排列,否则会水平左右排列
:顶栏容器
:侧边栏容器
:主要区域容器
:底栏容器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<style>
.el-header, .el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
}
.el-aside {
background-color: #D3DCE6;
color: #333;
text-align: center;
line-height: 200px;
}
.el-main {
background-color: #E9EEF3;
color: #333;
text-align: center;
line-height: 160px;
}
body > .el-container {
margin-bottom: 40px;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
line-height: 260px;
}
.el-container:nth-child(7) .el-aside {
line-height: 320px;
}
</style>
<body>
<div id="app">
<el-container>
<el-header>
标题
</el-header>
<el-container>
<el-aside width="200px">
菜单
</el-aside>
<el-container>
<el-main>
功能区域
</el-main>
<el-footer>
底部
</el-footer>
</el-container>
</el-container>
</el-container>
</div>
</body>
</html>
<script>
new Vue({
el:"#app"
})
</script>
【小结】
1:ElementUI介绍
ElementUI是一套基于VUE2.0的桌面端组件库,ElementUI提供了丰富的组件帮助开发人员快速构建功能强大、风格统一的页面。 做后台管理系统的开发
2:常用组件
(1)Container布局容器(用于页面布局)
(2)Dropdown下拉菜单(用于首页退出菜单)
(3)NavMenu导航菜单(用于左侧菜单)
(4)Tabel表格(用于列表展示)
(5)Pagination分页(用于列表分页展示)
(6)Message消息提示(用于保存、修改、删除的时候成功或失败提示)
(7)Tabs标签页(用于一个页面多个业务功能)
(8)Form表单(新增、修改时的表单,及表单验证)
【学习方法】
看官网,看案例,根据需求复制、粘贴、改(将复杂的代码简单化),看效果。
|