ssm整合
一、导包(pom.xml文件)
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 4.0.0
6
7 aaa
8 test_maven_qy97_03
9 1.0-SNAPSHOT
10
11 4.3.18.RELEASE
12
13
14
15
16
17 org.springframework
18 spring-core
19 ${spring.version}
20
21
22
23 org.springframework
24 spring-beans
25 ${spring.version}
26
27
28
29 org.springframework
30 spring-context
31 ${spring.version}
32
33
34
35 org.springframework
36 spring-tx
37 ${spring.version}
38
39
40
41 org.springframework
42 spring-web
43 ${spring.version}
44
45
46
47 org.springframework
48 spring-webmvc
49 ${spring.version}
50
51
52
53 org.springframework
54 spring-jdbc
55 ${spring.version}
56
57
58
59
60 org.mybatis
61 mybatis
62 3.4.6
63
64
65
66 org.mybatis
67 mybatis-spring
68 1.3.2
69
70
71
72
73 com.oracle
74 ojdbc6
75 6
76
77
78
79 commons-io
80 commons-io
81 1.3.2
82
83
84
85 commons-fileupload
86 commons-fileupload
87 1.2.1
88
89
90
91
92 com.fasterxml.jackson.core
93 jackson-core
94 2.9.8
95
96
97 com.fasterxml.jackson.core
98 jackson-annotations
99 2.9.8
100
101
102 com.fasterxml.jackson.core
103 jackson-databind
104 2.9.8
105
106
107
108
109 commons-dbcp
110 commons-dbcp
111 1.4
112
113
114
115
116 jstl
117 jstl
118 1.2
119
120
121
122
123
124
125
126
127
128 src/main/java
129
130 **/*.xml
131
132
133
134
135
136
二、准备数据库表
三、准备pojo(java类)也就是实体类,对应数据库
四、准备jdbc.properties文件
1 mysql:2 driver=com.mysql.jdbc.Driver3 url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-84 username=root5 password=admin6
7 oracle:8 driver=oracle.jdbc.driver.OracleDriver9 url=jdbc:oracle:thin:@localhost:1521:orcl10 user=scott11 password=tiger
五、applicationContext.xml配置文件(也就是spring主配置文件)
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"
5 xmlns:aop="http://www.springframework.org/schema/aop"
6
7 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">
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
步骤:
1、扫描service
2、加载jdbc
3、创建dbcp数据源连接池
4、创建mybatis的工厂类对象
5、在spring的工厂中生成dao接口的实现类对象
6、创建spring的事务管理器
7、声明以注解的方式配置声明式事务
8、配置事务通知
9、配置aop
六、spring-mvc配置文件
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:context="http://www.springframework.org/schema/context"
5 xmlns:mvc="http://www.springframework.org/schema/mvc"
6 xsi:schemaLocation="http://www.springframework.org/schema/beans7 http://www.springframework.org/schema/beans/spring-beans.xsd8 http://www.springframework.org/schema/context9 http://www.springframework.org/schema/context/spring-context.xsd10 http://www.springframework.org/schema/mvc11 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
12
13
14
15
16
17
18
19
20
21
步骤:
1:、配置controller扫描
2、配置注解驱动
3、配置视图解析器
七、dao层以及mapper实现
注:在applicationContext.xml中配置了自动扫描mapper,所有路径一定要保持一致,命名也是一样。
八、service层
根据所需要的业务逻辑来调用dao层的接口来实现业务处理。
九、controller层
控制层调用service来实现业务处理并且返回相对应的jsp页面以及重定向等。(注:jsp页面的路径问题,在spring-mvc配置文件中配置了视图解析的前缀和后缀,注意)
十、写自己所需要的jsp
这个并不是必须在最后写的,也可以先写一些会用到的,也可以在写controller的过程中,需要哪个页面然后就写哪个就好。
十一、最后部署到服务器上,注意jar包也要同时部署到服务器。