开发工具为idea,首先先看下搭建好之后的项目的结构,common-config 为项目环境的配置,因为在开发当中,有本地,测试,预生产,生产,四种环境,这样的package的时候不用修改配置,直接打包就ok
首先我们先建一个object项目,
然后在项目中 建一个 Module 名称为 antique
再在下面建三个小Module
antique-api, 主要是service 接口,entity数据库对于的类,还有一个commonUtil
antique-provider 主要是serviceImpl , mapper xml
antique-app 主要 controller
接下来我们开始引包,maven就是一个很好的jar包管理工具
antique 的pom
server-parent
com.wonder
1.0-SNAPSHOT
4.0.0
antique
pom
antique-api
antique-provider
antique-app
4.2.0.RELEASE
org.springframework
spring-core
${org.springframework.version}
org.springframework
spring-expression
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-tx
${org.springframework.version}
org.springframework
spring-jdbc
${org.springframework.version}
org.springframework
spring-orm
${org.springframework.version}
org.springframework
spring-oxm
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.springframework
spring-webmvc-portlet
${org.springframework.version}
org.springframework
spring-test
${org.springframework.version}
test
com.alibaba
druid
1.0.21
org.mybatis
mybatis
3.4.1
org.mybatis
mybatis-spring
1.3.0
jstl
jstl
1.2
com.alibaba
fastjson
1.2.13
javax.servlet
servlet-api
2.5
provided
org.aspectj
aspectjweaver
1.6.11
org.aspectj
aspectjrt
1.7.3
cglib
cglib
3.1
mysql
mysql-connector-java
5.1.30
log4j
log4j
1.2.17
commons-logging
commons-logging
1.1.3
com.github.pagehelper
pagehelper
4.1.3
org.slf4j
slf4j-log4j12
1.7.21
org.slf4j
slf4j-api
1.7.21
antique-api的pom代码
antique
com.wonder
1.0-SNAPSHOT
4.0.0
antique-api
4.2.0.RELEASE
org.springframework
spring-core
${org.springframework.version}
org.springframework
spring-expression
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-tx
${org.springframework.version}
org.springframework
spring-jdbc
${org.springframework.version}
org.springframework
spring-orm
${org.springframework.version}
org.springframework
spring-oxm
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.springframework
spring-webmvc-portlet
${org.springframework.version}
org.springframework
spring-test
${org.springframework.version}
test
com.alibaba
druid
1.0.21
org.mybatis
mybatis
3.4.1
org.mybatis
mybatis-spring
1.3.0
jstl
jstl
1.2
com.alibaba
fastjson
1.2.13
javax.servlet
servlet-api
2.5
provided
org.aspectj
aspectjweaver
1.6.11
org.aspectj
aspectjrt
1.7.3
cglib
cglib
3.1
mysql
mysql-connector-java
5.1.30
log4j
log4j
1.2.17
commons-logging
commons-logging
1.1.3
com.github.pagehelper
pagehelper
4.1.3
org.slf4j
slf4j-log4j12
1.7.21
org.slf4j
slf4j-api
1.7.21
antique-app的pom代码
antique
com.wonder
1.0-SNAPSHOT
4.0.0
antique-app
war
antique-app Maven Webapp
http://maven.apache.org
4.2.0.RELEASE
org.springframework
spring-core
${org.springframework.version}
org.springframework
spring-expression
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-tx
${org.springframework.version}
org.springframework
spring-jdbc
${org.springframework.version}
org.springframework
spring-orm
${org.springframework.version}
org.springframework
spring-oxm
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.springframework
spring-webmvc-portlet
${org.springframework.version}
org.springframework
spring-test
${org.springframework.version}
test
com.alibaba
druid
1.0.21
org.mybatis
mybatis
3.4.1
org.mybatis
mybatis-spring
1.3.0
jstl
jstl
1.2
com.alibaba
fastjson
1.2.13
javax.servlet
servlet-api
2.5
provided
org.aspectj
aspectjweaver
1.6.11
org.aspectj
aspectjrt
1.7.3
cglib
cglib
3.1
mysql
mysql-connector-java
5.1.30
log4j
log4j
1.2.17
commons-logging
commons-logging
1.1.3
com.github.pagehelper
pagehelper
4.1.3
org.slf4j
slf4j-log4j12
1.7.21
org.slf4j
slf4j-api
1.7.21
com.wonder
antique-api
${antique-api.version}
antique-app
org.apache.maven.plugins
maven-compiler-plugin
1.7
org.apache.maven.plugins
maven-war-plugin
2.1.1
false
${common.config}/src/main/resources/${env}
WEB-INF/classes
true
src/main/resources/
WEB-INF/classes
true
antique-provider pom代码
server-parent
com.wonder
1.0-SNAPSHOT
4.0.0
antique
pom
antique-api
antique-provider
antique-app
4.2.0.RELEASE
org.springframework
spring-core
${org.springframework.version}
org.springframework
spring-expression
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-tx
${org.springframework.version}
org.springframework
spring-jdbc
${org.springframework.version}
org.springframework
spring-orm
${org.springframework.version}
org.springframework
spring-oxm
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.springframework
spring-webmvc-portlet
${org.springframework.version}
org.springframework
spring-test
${org.springframework.version}
test
com.alibaba
druid
1.0.21
org.mybatis
mybatis
3.4.1
org.mybatis
mybatis-spring
1.3.0
jstl
jstl
1.2
com.alibaba
fastjson
1.2.13
javax.servlet
servlet-api
2.5
provided
org.aspectj
aspectjweaver
1.6.11
org.aspectj
aspectjrt
1.7.3
cglib
cglib
3.1
mysql
mysql-connector-java
5.1.30
log4j
log4j
1.2.17
commons-logging
commons-logging
1.1.3
com.github.pagehelper
pagehelper
4.1.3
org.slf4j
slf4j-log4j12
1.7.21
org.slf4j
slf4j-api
1.7.21
注意app 跟provider pom 最后面的build配置,打包使用,不可缺少
antique-app 的结构
接下来就是
resources applicationContext..xml 代码 spring配置
classpath*:jdbc.properties
classpath*:system.properties
主要是整合mybatis,配置jdbc.properties数据库参数properties,系统参数配置system.properties
mybatis xml配置
主要是jdbc数据库连接池配置 这里我使用的是druid连接池,扫描数据库表映射的xml文件
springMvc配置
text/plain; charset=UTF-8
application/json;charset=UTF-8
里面可以配置一些拦截器,页面跳转配置等
log4j 代码
log4j.rootCategory=, A1
log4j.rootLogger=DEBUG,A3,STDOUT
log4j.category.org.apache.log4j.net=INFO
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=[%p] [%l] %10.10c - %m%n
log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
log4j.appender.A1.MaxNumberOfRecords=700
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.file=${LOGS_PATH}/server.log
log4j.appender.A3.MaxFileSize=1024KB
log4j.appender.A3.MaxBackupIndex=10
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=\n\n[%-5p] %d{yyyy-MM-dd HH\:mm\:ss,SSS} method\:%l%n%m%n
这个是网上随便扒的一个
最后就是app的web.xml配置
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:spring/applicationContext.xml
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc/springmvc.xml
1
org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
classpath:log4j.properties
springmvc
/
index.jsp
30
对springmvc sping 配置
最后给大家看一下common-config的配置图
jdbc的配置代码
# JDBC Configuration
jdbcDriverClassName=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
jdbcUsername=root
jdbcPassword=root
# DBCP Pool settings
jdbcInitialSize=5
jdbcMaxActive=10
jdbcMaxIdle=5
jdbcMaxWait=30000
jdbcValidationQuery=select 1
简单的项目的框架代码就在这里了
下面的就靠自己去填充了