- 后台管理系统
以前的做法
com.taotao.pojo javaBean
com.taotao.dao 持久层
com.taotao.service 业务逻辑层
com.taotao.controller WEB层
如果使用分布式架构,代码的重用性很差
com.taotao.manage 聚合工程的父工程
com.taotao.manage.pojo 聚合工程子工程,用来存放javaBean
com.taotao.manage.mapper 聚合工程子工程,持久层
com.taotao.manage.service 聚合工程子工程,业务逻辑层
com.taotao.manage.web 聚合工程子工程,WEB层
当其他工程需要共用的bean,可以直接依赖子工程,这样就解决了代码重用性差的问题。
-
- 创建taotao-manage
创建聚合工程的父工程
只有taotao-parent和聚合工程的父工程,需要打pom
-
-
- 搭建taotao-pojo
-
-
-
- taotao-mapper
-
-
-
- taotao-service
-
-
-
- taotao-web
-
-
-
- 物理存放结构
-
-
-
- pom.xml文件
- 父工程
- pom.xml文件
-
-
-
-
- 子工程
-
-
-
- 搭建开发环境
- 所需要的技术
- 搭建开发环境
ssm:
spring+springMVC+mybatis
通用Mapper,分页助手
前端技术:
jQuery,easyUI
jsp,jstl
-
- 添加依赖
添加依赖的原则:添加到最底层使用的地方
子工程的依赖原则
webàserviceàmapperàpojo
taotao-manage | 配置所有子工程都要用的的依赖 | junit测试依赖,日志依赖,Tomcat插件,Apache通用工具组件 |
pojo | JavaBean所用的依赖 | JAP注解 |
mapper | Mapper所用的依赖 | mybatis依赖(@param这个注解), 通用Mapper |
service | service所用的依赖 | 分页助手。 (如果事务管理使用注解开发,需要把AOP的依赖添加到service) |
web | controller所用的依赖 | 容器启动需要加载的依赖和web编写时,所需要的依赖 |
-
-
- manage-pojo添加依赖
-
<dependencies>
<!-- 添加JPA注解 -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
-
-
- manage-mapper添加依赖
-
<dependencies>
<!-- 依赖pojo -->
<dependency>
<groupId>com.taotao.manage.pojo</groupId>
<artifactId>taotao-manage-pojo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<!-- 通用Mapper -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
</dependencies>
-
-
- manage-service添加依赖
-
<dependencies>
<!-- 依赖service -->
<dependency>
<groupId>com.taotao.manage.mapper</groupId>
<artifactId>taotao-manage-mapper</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- 分页助手 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
</dependency>
</dependencies>
-
-
- manage-web添加依赖
-
<dependencies>
<!-- 加入service依赖 -->
<dependency>
<groupId>com.taotao.manage.service</groupId>
<artifactId>taotao-manage-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Spring -->
<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>
<!-- mybatis整合spring依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp-spring</artifactId>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
-
-
- 配置Tomcat插件
-
需要配置到聚合工程的父工程 taotao-manage中
-
- 加入配置文件
配置文件结构
-
-
- 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_2_5.xsd"
id="MyWebApp" version="2.5">
<display-name>taotao-manage</display-name>
<!-- 启动spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
</context-param>
<!-- 使用监听器加载applicationContext文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 解决乱码问题 -->
<filter>
<filter-name>encodingFilter</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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- PUT、DELETE表单提交 -->
<filter>
<filter-name>HttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 加载springMVC -->
<servlet>
<servlet-name>taotao-manage</servlet-name>
<!-- 配置DispatcherServlet,springmvc入口 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/taotao-manage-servlet.xml</param-value>
</init-param>
<!-- 启动web容器就启动springMVC -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>taotao-manage</servlet-name>
<!-- 所有以rest开头的请求都进入springMVC -->
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>