微信开发准备第二步 springmvc mybatis项目结构搭建

网友投稿 239 2023-05-22


微信开发准备第二步 springmvc mybatis项目结构搭建

前面一篇有说道如何在MyEclipse中搭建maven项目,这里将继续介绍如何在搭建好的基础maven项目中引入我们常用的javaweb框架——SpringMVC!

①在建立好的maven项目中的pom.xml文件引入依赖,代码如下:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 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

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

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 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

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文件如下:

xmlns:web="http://java.sun.com/xml/ns/javaee" 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

http://springframework.org/schema/websocket http://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

false

/WEB-INF/common/head.jsp

xmlns:web="http://java.sun.com/xml/ns/javaee" 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

http://springframework.org/schema/websocket http://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

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配置文件,设置如下:

⑤在 resources下新建spring-mvc.xml配置文件,设置如下:

text/html;charset=UTF-8

UTF-8

32505856

4096

⑥在 resources下新建spring-mybatis.xml配置文件,设置如下:

com.cuiyongzhi.web.service.*

⑦在 resources下新建log4j.properties配置文件,用于日志的输出等级以及输出位置设置,设置如下:

到这里springmvc+mybatis的基本配置文件基本就完成了,大致的项目结构如下:

本篇主要以代码示例为主,基本的的项目搭建就记录到这里,下一篇我将简述在这个框架下的一些简单应用,感谢你的翻阅,如有疑问可以讨论!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java枚举_动力节点Java学院整理
下一篇:Java微信公众平台开发(1) 接入微信公众平台
相关文章

 发表评论

暂时没有评论,来抢沙发吧~