作者:魔蝎陈小琳 | 来源:互联网 | 2017-05-11 01:14
这篇文章主要为大家详细介绍了微信开发准备第二步,springmvc和mybatis项目结构的搭建,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
前面一篇有说道如何在MyEclipse中搭建maven项目,这里将继续介绍如何在搭建好的基础maven项目中引入我们常用的javaweb框架——SpringMVC!
①在建立好的maven项目中的pom.xml文件引入依赖,代码如下:
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
wechat.cuiyongzhi.com
wechat
war
0.0.1-SNAPSHOT
wechat
http://maven.apache.org</url>
org.springframework
spring-test
3.2.0.RELEASE
org.springframework
spring-webmvc
3.2.0.RELEASE
org.springframework
spring-core
3.2.0.RELEASE
org.mybatis
mybatis
3.1.1
org.mybatis
mybatis-spring
1.1.1
mysql
mysql-connector-java
5.1.21
junit
junit
4.11
test
com.alibaba
druid
0.2.9
org.aspectj
aspectjweaver
1.7.1
com.alibaba
fastjson
1.2.7
commons-fileupload
commons-fileupload
1.2.2
javax.servlet
servlet-api
3.0-alpha-1
javax.servlet.jsp
jsp-api
2.1
provided
javax.servlet
jstl
1.2
log4j
log4j
1.2.17
wechat
②修改项目路径下的web.xml文件如下:
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd"
id="WebApp_ID" version="3.0">
com.cuiyongzhi.wechat
contextConfigLocation
classpath:spring.xml,classpath:spring-mybatis.xml
log4jConfigLocation
classpath:log4j.properties
org.springframework.web.util.Log4jConfigListener
spring.profiles.active
dev
spring.profiles.default
dev
spring.liveBeansView.mbeanDomain
dev
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
spring监听器
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
spring mvc servlet
springMvc
org.springframework.web.servlet.DispatcherServlet
spring mvc 配置文件
contextConfigLocation
classpath:spring-mvc.xml
1
interface_url-init_servlet
com.cuiyongzhi.web.start.InterfaceUrlIntiServlet
1
springMvc
/
/index.jsp
300
404
/WEB-INF/error/error.jsp
500
/WEB-INF/error/error.jsp
default
*.css
default
*.gif
default
*.jpg
default
*.js
default
*.xhtml
default
*.html
DruidWebStatFilter
com.alibaba.druid.support.http.WebStatFilter
exclusions
*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
DruidWebStatFilter
/*
DruidStatView
com.alibaba.druid.support.http.StatViewServlet
resetEnable
true
loginUsername
cuiyongzhi
loginPassword
123456
DruidStatView
/druid/*
jspConfiguration
*.jsp
false
/WEB-INF/common/head.jsp
③添加数据库配置信息,这里项目配置的数据库为MySQL,在 resources下新建config.properties配置文件,设置如下:
validatiOnQuery=SELECT 1
jdbc_url=jdbc:mysql://127.0.0.1:3306/wechat?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc_username=root
jdbc_password=123456789
④在 resources下新建spring.xml配置文件,设置如下:
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
⑤在 resources下新建spring-mvc.xml配置文件,设置如下:
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
text/html;charset=UTF-8
UTF-8
32505856
4096
⑥在 resources下新建spring-mybatis.xml配置文件,设置如下:
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
com.cuiyongzhi.web.service.*
⑦在 resources下新建log4j.properties配置文件,用于日志的输出等级以及输出位置设置,设置如下:
本篇主要以代码示例为主,基本的的项目搭建就记录到这里,下一篇我将简述在这个框架下的一些简单应用,感谢你的翻阅,如有疑问可以讨论!
以上就是微信开发之springmvc mybatis项目结构搭建的java代码详解的详细内容,更多请关注php中文网其它相关文章!