来源:一叶知秋
作者:知秋
Migo商城2.0 框架搭建
1.0版本github链接:https://github.com/muyinchen/migoShop
2.0版本github链接:https://github.com/muyinchen/migoshop2.0
开发技术
- Spring
- Springmvc
- Mybatis
- Redis
- Solr
- RabbitMQ
- Dubbohttpclient(调用系统服务)
- nginx
- fastdfs 5.0.5
- MysqL
环境
- IDEA 2016.1.3(64)
- maven 3.2.9
- tomcat 7
- jdk 1.7
- MySQL 5.6
- nginx 1.11.4
- redis 3.2.4
- solr 6.2.1
构建maven项目
注意是pom
4.0.0
com.migo
parent
2.0-SNAPSHOT
pom
4.12
4.1.3.RELEASE
3.2.8
1.2.2
1.2.15
5.1.32
1.6.4
2.4.2
1.0.9
4.3.5
1.2
2.5
2.0
2.5
3.3.2
1.3.2
3.3
4.1.6
0.9.1
1.3.1
2.7.2
6.2.1
2.5.3
3.4.7
0.1
5.11.2
2.3.23
2.2.2
joda-time
joda-time
${joda-time.version}
org.apache.commons
commons-lang3
${commons-lang3.version}
org.apache.commons
commons-io
${commons-io.version}
commons-net
commons-net
${commons-net.version}
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
org.apache.httpcomponents
httpclient
${httpclient.version}
org.quartz-scheduler
quartz
${quartz.version}
junit
junit
${junit.version}
test
org.slf4j
slf4j-log4j12
${slf4j.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
${mybatis.spring.version}
com.github.miemiedev
mybatis-paginator
${mybatis.paginator.version}
com.github.pagehelper
pagehelper
${pagehelper.version}
mysql
mysql-connector-java
${mysql.version}
com.alibaba
druid
${druid.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-aspects
${spring.version}
org.springframework
spring-jms
${spring.version}
org.springframework
spring-context-support
${spring.version}
jstl
jstl
${jstl.version}
javax.servlet
servlet-api
${servlet-api.version}
provided
javax.servlet
jsp-api
${jsp-api.version}
provided
commons-fileupload
commons-fileupload
${commons-fileupload.version}
redis.clients
jedis
${jedis.version}
org.apache.solr
solr-solrj
${solrj.version}
com.alibaba
dubbo
${dubbo.version}
org.apache.zookeeper
zookeeper
${zookeeper.version}
com.github.sgroschupf
zkclient
${zkclient.version}
org.apache.activemq
activemq-all
${activemq.version}
org.freemarker
freemarker
${freemarker.version}
${project.artifactId}
org.apache.maven.plugins
maven-resources-plugin
2.7
UTF-8
org.apache.maven.plugins
maven-compiler-plugin
3.2
1.7
UTF-8
org.apache.tomcat.maven
tomcat7-maven-plugin
2.2
创建migo-common
此为整个项目的通用模块
pom:
4.0.0
com.migo
parent
2.0-SNAPSHOT
common
2.0-SNAPSHOT
jar
joda-time
joda-time
org.apache.commons
commons-lang3
org.apache.commons
commons-io
commons-net
commons-net
com.fasterxml.jackson.core
jackson-databind
org.apache.httpcomponents
httpclient
org.quartz-scheduler
quartz
junit
junit
test
org.slf4j
slf4j-log4j12
创建migo-manage
此为后台管理系统
使用Maven的聚合将所有的子工程进行创建
子工程之间的依赖关系
migo-manage-web --> migo-manage-service --> migo-manage-mapper --> migo-manage-pojo
导入依赖
导入依赖的原则:
- 所有的工程都需要的依赖应该在聚合工程(migo-manage)中导入。
- 在使用依赖的最底层导入。
- 运行时所需要的依赖在web工程中加入。
注意:
聚合工程的tomcat插件要在聚合工程中导入,migo-manage中导入
有些依赖包的用法会单独开博文讲解用法
migo-manage pom
4.0.0
manage-pojo
manage-mapper
manage-service
manage-web
com.migo
parent
2.0-SNAPSHOT
manage
2.0-SNAPSHOT
pom
com.migo
common
2.0-SNAPSHOT
junit
junit
test
org.slf4j
slf4j-log4j12
org.apache.commons
commons-lang3
org.apache.commons
commons-io
org.apache.tomcat.maven
tomcat7-maven-plugin
8081
/
manage-pojo pom
manage
com.migo
2.0-SNAPSHOT
4.0.0
manage-pojo
jar
javax.persistence
persistence-api
1.0
manage-service pom
manage
com.migo
2.0-SNAPSHOT
4.0.0
manage-service
jar
com.migo
manage-mapper
2.0-SNAPSHOT
org.springframework
spring-webmvc
com.github.pagehelper
pagehelper
com.github.jsqlparser
jsqlparser
redis.clients
jedis
org.springframework.amqp
spring-rabbit
1.6.3.RELEASE
manage-web pom
manage
com.migo
2.0-SNAPSHOT
4.0.0
manage-web
war
com.migo
manage-service
2.0-SNAPSHOT
org.springframework
spring-jdbc
org.springframework
spring-aspects
org.mybatis
mybatis-spring
mysql
mysql-connector-java
com.fasterxml.jackson.core
jackson-databind
com.alibaba
druid
jstl
jstl
javax.servlet
servlet-api
provided
javax.servlet
jsp-api
provided
commons-fileupload
commons-fileupload
1.3.1
joda-time
joda-time
框架整合思路
ssm框架整合思路: Dao层:mybatis、spring、mybatis和spring的整合包。
Mybatis:mybatis-config.xml,文件可以为空,但是文件必须存在。
applicationContext-dao.xml:数据库连接池、SqlSessionFactory(整合包中类),配置一个包扫描器,扫描Mapper接口,生成代理对象。
Service层:spring
applicationContext-service.xml:扫描@Service注解的类,创建对象放到spring容器中。 事务配置:
applicationContext-trans.xml:配置切面、切点、配置事务管理器。
表现层:springmvc 配置springmvc.xml:配置注解驱动、视图解析器,配置包扫描器@Controller注解 的类。
web.xml 配置初始化spring容器 配置前端控制器DispatcherServlet 配置post乱码过滤器
整合通用mapper
3.2.0版本以后配置更简单,以前的拦截器不能继续使用
纯Spring配置方式:
创建web.xml
migo-manage
contextConfigLocation
classpath:spring/applicationContext*.xml
org.springframework.web.context.ContextLoaderListener
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF8
encodingFilter
/*
HttpMethodFilter
org.springframework.web.filter.HttpPutFormContentFilter
HttpMethodFilter
/*
HiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
HiddenHttpMethodFilter
/*
migo-manage
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/springmvc.xml
1
migo-manage
/rest/*
index.jsp
导入静态页面
写个通用跳转页面
package com.migo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Author 知秋
* Created by kauw on 2016/11/7.
* 通用页面的跳转
*/
@Controller
public class PageController {
@RequestMapping(value = "/page/{pageName}",method = RequestMethod.GET)
public String tpage(@PathVariable String pageName){
return pageName;
}
}
效果页面展示
更多内容请关注:极乐科技