您好,欢迎来到六九路网。
搜索
您的当前位置:首页SpringMVC和Hibernate整合

SpringMVC和Hibernate整合

来源:六九路网
SpringMVC和Hibernate整合

分类: JAVA2011-08-15 16:24 18775人阅读 评论(4) 收藏 举报

hibernatespringencodingcharactermvc

hibernate由spring管理,配置文件如下: applicationContext.xml

[html] view plaincopy

1.

2. 6. xmlns:context=\"http://www.springframework.org/schema/context\" 7. xsi:schemaLocation=\"http://www.springframework.org/schema/beans 8. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 9. http://www.springframework.org/schema/aop

10. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 11. http://www.springframework.org/schema/tx

12. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 13. http://www.springframework.org/schema/context

14. http://www.springframework.org/schema/context/spring-context-3.0.xsd\"

>

15. 16.

17. \" scoped-proxy=\"targetClass\">

18.

19. 20.

21.

22. anagerDataSource\">

23. 24. 名?useUnicode=true&characterEncoding=utf8\"/> 25. 26. 27.

28.

29. tation.AnnotationSessionFactoryBean\">

30.

31. 32.

33. org.hibernate.dialect.MySQLDia

lect

34. true 35. update 36. 37. 38.

39. 40.

41. 中间写入hibernate注解的实体 42. 43.

44. HibernateTransactionManager\">

45. 46.

47.

48. 49.

有了applicationContext再在web.xml在配置一下便可同时使用spring和hibernate了,但是要使用spring mvc ,还得在web里做一点手脚,具体如下:

[html] view plaincopy

1.

2. /java.sun.com/xml/ns/javaee\" xmlns:web=\"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\" version=\"2.5\"> 3. 4.

5. spring config 6. contextConfigLocation

7. /WEB-INF/applicationContext.xml 8. 9.

10. spring listerner

11. org.springframework.web.context.ContextLoaderListeneristener-class> 12. 13.

14. 15.

16. springmvc

17. org.springframework.web.servlet.DispatcherServlett-class>

18. 2 19. 20.

21. springmvc 22. 23. *.do 24. 25. 26.

27. 28.

29. Spring character encoding filter 30. org.springframework.web.filter.CharacterEncodingFilter

31.

32. encoding 33. utf-8 34. 35. 36.

37. Spring character encoding filter 38. /* 39. 40.

41. 42.

43. 404

44. /error/404.html 45. 46.

47. 48.

49. 30 50. 51.

52. login.jsp 53. .

如上面配置文件的注释所说,由于配置了spring mvc ,还得有相关的文件,以上面的配置对应的文件名为: springmvc-servlet.xml

[html] view plaincopy

1.

2. 3. xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"http://ww

w.springframework.org/schema/p\"

4. xmlns:context=\"http://www.springframework.org/schema/context\" 5. xsi:schemaLocation=\"http://www.springframework.org/schema/beans 6. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 7. http://www.springframework.org/schema/context

8. http://www.springframework.org/schema/context/spring-context-2.5.xsd\"> 9. 10.

11. 12. 13.

14. 15. 16. class=\"org.springframework.web.servlet.mvc.annotation.AnnotationMeth

odHandlerAdapter\">

17.

18. 19. 20. 21. class=\"org.springframework.http.converter.json.MappingJa

cksonHttpMessageConverter\">

22. 23.

24. application/json;charset=UTF-8 25. 26. 27. 28. 29. 30. 31. 32.

33. 34. 35. class=\"org.springframework.web.multipart.commons.CommonsMultipartRes

olver\">

36. 37. UTF-8 38. 39. 40.

41. 42. 43. class=\"org.springframework.web.servlet.view.InternalResourceViewReso

lver\"

44. p:prefix=\"\" p:suffix=\".jsp\" /> 45. 46.

47.

按照本文所提到的配置文件配置的话,三个文件全部都放在web-inf里面,其中springmvc-servlet.xml里面配置的信息转换用到了两个外加的包 jackson-core-asl-1.4.2.jar jackson-mapper-asl-1.4.2.jar

本文章主要是配置文件的编写,所以不涉及JAVA代码

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 69lv.com 版权所有 湘ICP备2023021910号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务