没有合适的资源?快使用搜索试试~ 我知道了~
首页ssm框架整合及Rest风格接口实现
ssm框架整合及Rest风格接口实现

1.基于Maven的SSM框架整合即Spring+SpringMVC+Mybatis三大框架进行整合。 2.REST接口的实现示例 PDF文档。
资源详情
资源评论
资源推荐

ssm 框架整合及 Rest 风格接口实现
1.
前言
SSM 框架整合即 Spring+SpringMVC+Mybatis 三大框架进行整合。属于现在 Java
项目主流的框架选择。
关于这三大框架的介绍,本篇幅不做说明。项目中结合了 Maven 的使用。
关于 Eclipse 构建 Maven 项目详情文章:
http://blog.csdn.net/it_faquir/article/details/54562242
2.Maven
依赖
首先创建一个 Maven 的 Web 项目。这里将其命名为“SSMIntegration”及 SMM
整合。
通过 Maven 的 pom.xml 加入各所需 jar 包。
1. <properties>
2. <spring-version>4.3.5.RELEASE</spring-version>
3. </properties>
4. <dependencies>
5. <dependency>
6. <groupId>junit</groupId>
7. <artifactId>junit</artifactId>
8. <version>4.12</version>
9. <scope>test</scope>
10. </dependency>
11. <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api
-->
12. <dependency>
13. <groupId>javax.servlet</groupId>
14. <artifactId>servlet-api</artifactId>
15. <version>2.5</version>
16. </dependency>
17. <!-- spring & mvc start -->
18. <!-- http://projects.spring.io/spring-framework/ -->
19. <dependency>
20. <groupId>org.springframework</groupId>
21. <artifactId>spring-context</artifactId>

22. <version>${spring-version}</version>
23. </dependency>
24. <!--
https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
25. <dependency>
26. <groupId>org.springframework</groupId>
27. <artifactId>spring-webmvc</artifactId>
28. <version>${spring-version}</version>
29. </dependency>
30.
31. <!--
https://mvnrepository.com/artifact/org.springframework/spring-test -->
32. <dependency>
33. <groupId>org.springframework</groupId>
34. <artifactId>spring-test</artifactId>
35. <version>${spring-version}</version>
36. </dependency>
37.
38.
<!-- datasource 必须 -->
39. <!--
https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
40. <dependency>
41. <groupId>org.springframework</groupId>
42. <artifactId>spring-jdbc</artifactId>
43. <version>${spring-version}</version>
44. </dependency>
45. <!-- spring & mvc end -->
46.
47.
48. <!-- mybaits start -->
49. <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
50. <dependency>
51. <groupId>org.mybatis</groupId>
52. <artifactId>mybatis</artifactId>
53. <version>3.4.1</version>
54. </dependency>
55.
<!-- spring 整合 mybatis 必备 -->
56. <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring
-->
57. <dependency>
58. <groupId>org.mybatis</groupId>
59. <artifactId>mybatis-spring</artifactId>
60. <version>1.3.0</version>
61. </dependency>

62. <!-- mybatis end -->
63.
64. <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
65. <dependency>
66. <groupId>com.alibaba</groupId>
67. <artifactId>druid</artifactId>
68. <version>1.0.26</version>
69. </dependency>
70. <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java
-->
71. <dependency>
72. <groupId>mysql</groupId>
73. <artifactId>mysql-connector-java</artifactId>
74. <version>6.0.5</version>
75. </dependency>
76.
77.
<!-- 使用@RequestBody @ResponseBody 时得用到下面两 jar 包 -->
78. <!--
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
79. <dependency>
80. <groupId>com.fasterxml.jackson.core</groupId>
81. <artifactId>jackson-core</artifactId>
82. <version>2.8.5</version>
83. </dependency>
84. <!--
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
-->
85. <dependency>
86. <groupId>com.fasterxml.jackson.core</groupId>
87. <artifactId>jackson-databind</artifactId>
88. <version>2.8.5</version>
89. </dependency>
90. </dependencies>
上面加入了 Spring/SpringMVC/Mybatis 及其它所需的依赖,其中
jackson-core
和 jackson-databind 千万别忘了,
否则你会发现 Spring 无法解析传来 json 数据
,
具
体请看注释。
3.各种配置
web.xml

1. <?xml version="1.0" encoding="UTF-8"?>
2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3. xmlns="http://java.sun.com/xml/ns/javaee"
4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5. version="2.5">
6.
7. <display-name>SSHIntergration</display-name>
8. <welcome-file-list>
9. <welcome-file>index.jsp</welcome-file>
10. </welcome-file-list>
11.
12. <!-- needed for ContextLoaderListener -->
13. <context-param>
14. <param-name>contextConfigLocation</param-name>
15. <param-value>classpath:applicationContext.xml</param-value>
16. </context-param>
17.
18. <!-- Bootstraps the root web application context before servlet
initialization -->
19. <listener>
20.
<listener-class>org.springframework.web.context.ContextLoaderListener</l
istener-class>
21. </listener>
22.
23. <!-- SpringMVC servlet -->
24. <servlet>
25. <servlet-name>springDispatcherServlet</servlet-name>
26.
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servle
t-class>
27. <init-param>
28. <param-name>contextConfigLocation</param-name>
29. <param-value>classpath:applicationContext-web.xml</param-value>
30. </init-param>
31. <load-on-startup>1</load-on-startup>
32. </servlet>
33. <servlet-mapping>
34. <servlet-name>springDispatcherServlet</servlet-name>
35. <url-pattern>/</url-pattern>
36. </servlet-mapping>
37.
38.
<!-- 防止乱码 -->
剩余18页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1