作者:爱你无丶止境空间 | 来源:互联网 | 2024-12-21 12:56
ssm 框架整合及工程分层
1.先创建一个新的 project
1.1配置pom.xml
4.0.0
com.itheima
day58
1.0-SNAPSHOT
ssm-domain
ssm-dao
ssm-service
ssm-web
pom
UTF-8
UTF-8
5.0.2.RELEASE
1.6.6
1.2.12
5.1.6
3.4.5
1.6.8
4.12
2.0
2.5
1.2
2.9.7
1.3.0
1.0.9
org.springframework
spring-context
${spring.version}
org.aspectj
aspectjweaver
${aspectjweaver.version}
org.springframework
spring-webmvc
${spring.version}
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
org.springframework
spring-jdbc
${spring.version}
javax.servlet
servlet-api
${servlet-api.version}
provided
javax.servlet.jsp
jsp-api
${jsp-api.version}
provided
jstl
jstl
${jstl.version}
mysql
mysql-connector-java
${mysql.version}
runtime
org.springframework
spring-test
${spring.version}
junit
junit
${junit.version}
test
log4j
log4j
${log4j.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
slf4j-log4j12
${slf4j.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
${mybatis-spring.version}
com.alibaba
druid
${druid.version}
2. 在项目里创建ssm-domain ,用于管理java bean;
2.1配置pom.xml文件:
day58
com.itheima
1.0-SNAPSHOT
4.0.0
ssm-domain
jar
com.fasterxml.jackson.core
jackson-databind
2.2 创建java目录每层的父目录都相同,然后创建对应的javabean;
3.在这个项目里创建ssm-dao 层
3.1 配置pom.xml文件
day58
com.itheima
1.0-SNAPSHOT
4.0.0
ssm-dao
jar
com.itheima
ssm-domain
1.0-SNAPSHOT
org.mybatis
mybatis
org.mybatis
mybatis-spring
com.alibaba
druid
mysql
mysql-connector-java
org.springframework
spring-jdbc
org.springframework
spring-context
log4j
log4j
org.slf4j
slf4j-api
org.slf4j
slf4j-log4j12
3.2 创建java目录 创建dao接口
3.3在resources里创建dao的配置文件 spring-dao.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
4.在项目里创建ssm-service 层
4.1配置pom.xml文件
day58
com.itheima
1.0-SNAPSHOT
4.0.0
ssm-service
jar
com.itheima
ssm-dao
1.0-SNAPSHOT
org.springframework
spring-context
org.springframework
spring-jdbc
org.aspectj
aspectjweaver
4.2 创建java目录 service 创建Service接口和实现类
4.3在resources里创建service的配置文件 spring-service.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cOntext="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
5.在项目里创建 ssm-web 层
5.1配置pom.xml文件
day58
com.itheima
1.0-SNAPSHOT
4.0.0
ssm-web
war
com.itheima
ssm-service
1.0-SNAPSHOT
org.springframework
spring-webmvc
com.fasterxml.jackson.core
jackson-databind
javax.servlet
servlet-api
provided
javax.servlet.jsp
jsp-api
provided
jstl
jstl
5.2 在创建java目录 controller 创建Controller类
5.3在resources里创建web的配置文件 spring-web.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cOntext="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
5.配置webapp/WEB-INF/web.xml文件
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
login.jsp
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:spring-*.xml
1
dispatcherServlet
/
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
encodingFilter
/*