首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

IoC器皿+Web层框架+ORM框架的实现

2012-10-29 
IoC容器+Web层框架+ORM框架的实现下载地址:http://www.iteye.com/topic/1125898一个IoC容器+Web层框架+ORM

IoC容器+Web层框架+ORM框架的实现



下载地址:http://www.iteye.com/topic/1125898


一个IoC容器+Web层框架+ORM框架的简单实现(适用于学习用) 类似于SSH实现。

?

?

在学习期间写的,实现相对简单。欢迎下载。

?

涉及技术点:

? ? 反射、注解、配置文件、动态代理

实现了:

? ? IoC AOP Web层框架 ORM框架 。

?

?

1、Web层代码示例:

?

Java代码?
  1. package?cn.javass.test.action;??
  2. ??
  3. import?cn.javass.framework.ioc.annotation.IInject;??
  4. import?cn.javass.framework.web.annotation.IAction;??
  5. import?cn.javass.framework.web.annotation.IGoto;??
  6. import?cn.javass.framework.web.core.Action;??
  7. import?cn.javass.framework.web.core.ActionContext;??
  8. import?cn.javass.test.model.UserModel;??
  9. import?cn.javass.test.service.UserService;??
  10. @IAction(path="/user",??
  11. ?????????result={@IGoto(key="success",path="test.jsp")}??
  12. ????????)??
  13. public?class?UserAction?implements?Action{??
  14. ????@IInject(id="userService")??
  15. ????private?UserService?userService;??
  16. ??
  17. ????public?void?setUserService(UserService?userService)?{??
  18. ????????this.userService?=?userService;??
  19. ????}??
  20. ??????
  21. ????private?UserModel?um?=?new?UserModel();??
  22. ??
  23. ????@Override??
  24. ????public?String?execute()?{??
  25. ????????System.out.println("======="+um.toString());??
  26. ????????try{??
  27. ????????????userService.save(um);??
  28. ????//??????userService.save(um);??
  29. ????????}catch?(Exception?e)?{??
  30. ????????????System.out.println(e.getMessage());??
  31. ????????}??
  32. ??????????
  33. ????????um.getAddress().setAddress("zhangjavassp");??
  34. ????????ActionContext.getContext().put("haha",?"hahahhahaa");??
  35. ????//??userService.save(um);??
  36. ????????return?"success";??
  37. ????}??
  38. ??
  39. ????public?UserModel?getUm()?{??
  40. ????????return?um;??
  41. ????}??
  42. ??
  43. ????public?void?setUm(UserModel?um)?{??
  44. ????????this.um?=?um;??
  45. ????}??
  46. ??????
  47. }??

?

?

2、DAO层代码示例

?

Java代码?
  1. package?cn.javass.test.dao.impl;??
  2. ??
  3. import?cn.javass.framework.ioc.annotation.IService;??
  4. import?cn.javass.framework.ioc.annotation.Scope;??
  5. import?cn.javass.framework.orm.impl.BaseDAOImpl;??
  6. import?cn.javass.test.dao.UserDao;??
  7. ??
  8. ??
  9. @IService(id="userDao",scope=Scope.singleton)??
  10. public?class?UserDaoImpl?extends?BaseDAOImpl?implements?UserDao{??
  11. ??????
  12. }??

?

?

3、服务层代码示例

?

Java代码?
  1. package?cn.javass.test.service.impl;??
  2. ??
  3. import?java.util.List;??
  4. ??
  5. import?cn.javass.framework.aop.annotation.IInterceptor;??
  6. import?cn.javass.framework.aop.transaction.TransactionManagerInterceptor;??
  7. import?cn.javass.framework.ioc.annotation.IInject;??
  8. import?cn.javass.framework.ioc.annotation.IService;??
  9. import?cn.javass.framework.ioc.annotation.Scope;??
  10. import?cn.javass.test.dao.UserDao;??
  11. import?cn.javass.test.interceptor.MyInterceptor;??
  12. import?cn.javass.test.model.UserModel;??
  13. import?cn.javass.test.service.UserService;??
  14. ??
  15. ??
  16. @IService(id="userService")??
  17. public?class?UserServiceImpl?implements?UserService{??
  18. ??????
  19. ????@IInject(id="userDao")??
  20. ????private?UserDao?userDao?;??
  21. ??????
  22. ??
  23. ????public?void?setUserDao(UserDao?userDao)?{??
  24. ????????this.userDao?=?userDao;??
  25. ????}??
  26. ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
  27. ????@Override??
  28. ????public?boolean?delete(UserModel?um)?{??
  29. ????????return?this.userDao.delete(um);??
  30. ????}??
  31. ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
  32. ????@Override??
  33. ????public?List<UserModel>?getAll(UserModel?um)?{??
  34. ????????return?this.userDao.getAll(um.getClass());??
  35. ????}??
  36. ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
  37. ????@Override??
  38. ????public?boolean?save(UserModel?um)?{??
  39. ????????return?this.userDao.save(um);??
  40. ????}??
  41. ??
  42. }??

?

?

学习期间写的,实现相对简单。

热点排行