我的代码Spring SpringMvc 30 + MyBatis 整合.docx
《我的代码Spring SpringMvc 30 + MyBatis 整合.docx》由会员分享,可在线阅读,更多相关《我的代码Spring SpringMvc 30 + MyBatis 整合.docx(20页珍藏版)》请在冰豆网上搜索。
我的代码SpringSpringMvc30+MyBatis整合
我的代码:
SpringSpringMvc3.0+MyBatis整合
一、使用的jar包就不详细讲解了,下载了Mybatis和Spring的jar包基本上都添加上去了、
一图概括:
(这是我使用的ar包,有些不是Mybatis和Spring的)
二、web.xml配置文件
1.
xml version="1.0" encoding="UTF-8"?
>
2.xsi="http:
//www.w3.org/2001/XMLSchema-instance"
3. xmlns=" xmlns:
web="
4. xsi:
schemaLocation="
5. id="WebApp_ID" version="2.5">
6. WeShare
7.
8. /jumper.html
9.
10.
-- 加载spring容器配置 -->
11.
12. org.springframework.web.context.ContextLoaderListener
13.
14.
-- 设置Spring容器加载配置文件路径 (主要配置都在这里面) -->
15.
16. contextConfigLocation
17. /WEB-INF/applicationContext.xml
18.
19.
20.
21.
-- 配置Spring核心控制器 -->
22.
23. web
24. org.springframework.web.servlet.DispatcherServlet
25.
-- 不指定 会自动找web.xml相同路径下 web-servlet.xml文件 -->
26.
--
27.
28. contextConfigLocation
29. /WEB-INF/dispatcher.xml
30.
31. -->
32. 1
33.
34.
35. web
36. *.do
37.
38.
39. web
40. *.action
41.
42.
43.
44.
-- 解决工程编码过滤器 -->
45.
46. characterEncodingFilter
47. org.springframework.web.filter.CharacterEncodingFilter
48.
49. encoding
50. UTF-8
51.
52.
53.
54. characterEncodingFilter
55. /*
56.
57.
58.
-- dwr 添加配置 -->
59.
60. dwr-invoker
61. org.directwebremoting.servlet.DwrServlet
62.
63.
64. debug
65. false
66.
67.
68.
69. dwr-invoker
70. /dwr/*
71.
72.
73.
74.
75. java.lang.Throwable
76. /common/jsp/error.jsp
77.
78.
79. 403
80. /common/jsp/error403.jsp
81.
82.
83. 404
84. /common/jsp/error404.jsp
85.
86.
87.
三、
--配置Spring核心控制器-->
web
org.springframework.web.servlet.DispatcherServlet
--不指定会自动找web.xml相同路径下web-servlet.xml文件-->
--
contextConfigLocation
/WEB-INF/dispatcher.xml
-->
1
这个我使用的是默认的web-servlet.xml文件.如下:
1.
xml version="1.0" encoding="UTF-8"?
>
2.
3.//www.springframework.org/schema/beans"
4. xmlns:
tx="http:
//www.springframework.org/schema/tx"
5. xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
6. xmlns:
context="http:
//www.springframework.org/schema/context"
7. xmlns:
aop="http:
//www.springframework.org/schema/aop"
8. xmlns:
p="http:
//www.springframework.org/schema/p"
9. xsi:
schemaLocation="http:
//www.springframework.org/schema/beans
10. http:
//www.springframework.org/schema/beans/spring-beans.xsd
11. http:
//www.springframework.org/schema/tx
12. http:
//www.springframework.org/schema/tx/spring-tx.xsd
13. http:
//www.springframework.org/schema/context
14. http:
//www.springframework.org/schema/context/spring-context.xsd
15. http:
//www.springframework.org/schema/aop
16. http:
//www.springframework.org/schema/aop/spring-aop.xsd">
17.
18.
-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
19.
20.
21.
-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
22.
23.
24.
25.
26.
27. component-scan base-package="com.weshare.**.web"/>
28.
-- /hrtiaoxin/src/java/com/guohualife/ hr/pfc/ web/controller/HrDeptMarkController.java -->
29.
四:
applicationContext.xml文件:
1.
xml version="1.0" encoding="UTF-8"?
>
2.//www.springframework.org/schema/beans"
3. xmlns:
tx="http:
//www.springframework.org/schema/tx"
4. xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
5. xmlns:
context="http:
//www.springframework.org/schema/context"
6. xmlns:
aop="http:
//www.springframework.org/schema/aop"
7. xmlns:
p="http:
//www.springframework.org/schema/p"
8. xsi:
schemaLocation="http:
//www.springframework.org/schema/beans
9. http:
//www.springframework.org/schema/beans/spring-beans.xsd
10. http:
//www.springframework.org/schema/tx
11. http:
//www.springframework.org/schema/tx/spring-tx.xsd
12. http:
//www.springframework.org/schema/context
13. http:
//www.springframework.org/schema/context/spring-context.xsd
14. http:
//www.springframework.org/schema/aop
15. http:
//www.springframework.org/schema/aop/spring-aop.xsd">
16.
17.
18.
-- properties配置文件 -->
19. 20. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
21.
-- 是否忽略不可解析的 -->
22.
23.
-- 多个locations, 单个location -->
24.
25.
26. /WEB-INF/config/config.properties
27. /WEB-INF/config/urlAddress.properties
28.
--
29. /WEB-INF/platform/config/config.properties
30. /WEB-INF/config/config.properties
31. /WEB-INF/hr/config/config.properties
32. -->
33.
34.
35.
36.
37.
-- 文件上传 -->
38. defaultEncoding="UTF-8" >
39.
40.
-- 加载 其他xml文件 -->
41.
42.
43.
44.
45.
46.
包含的其他4个xml文件:
4.1:
aC-common.xml
1.
xml version="1.0" encoding="UTF-8"?
>
2.//www.springframework.org/schema/beans"
3. xmlns:
tx="http:
//www.springframework.org/schema/tx"
4. xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
5. xmlns:
context="http:
//www.springframework.org/schema/context"
6. xmlns:
aop="http:
//www.springframework.org/schema/aop"
7. xmlns:
p="http:
//www.springframework.org/schema/p"
8. xsi:
schemaLocation="http:
//www.springframework.org/schema/beans
9. http:
//www.springframework.org/schema/beans/spring-beans.xsd
10. http:
//www.springframework.org/schema/tx
11. http:
//www.springframework.org/schema/tx/spring-tx.xsd
12. http:
//www.springframework.org/schema/context
13. http:
//www.springframework.org/schema/context/spring-context.xsd
14. http:
//www.springframework.org/schema/aop
15. http:
//www.springframework.org/schema/aop/spring-aop.xsd">
16.
17. component-scan base-package="com.weshare.*.api.dao">
component-scan>
18. component-scan base-package="com.weshare.*.api.service">
component-scan>
19. component-scan base-package="mon.utils">
component-scan>
20.
21.
22.
23.
24.
25.