IoC器皿+Web层框架+ORM框架的实现
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代码?
- package?cn.javass.test.action;??
- ??
- import?cn.javass.framework.ioc.annotation.IInject;??
- import?cn.javass.framework.web.annotation.IAction;??
- import?cn.javass.framework.web.annotation.IGoto;??
- import?cn.javass.framework.web.core.Action;??
- import?cn.javass.framework.web.core.ActionContext;??
- import?cn.javass.test.model.UserModel;??
- import?cn.javass.test.service.UserService;??
- @IAction(path="/user",??
- ?????????result={@IGoto(key="success",path="test.jsp")}??
- ????????)??
- public?class?UserAction?implements?Action{??
- ????@IInject(id="userService")??
- ????private?UserService?userService;??
- ??
- ????public?void?setUserService(UserService?userService)?{??
- ????????this.userService?=?userService;??
- ????}??
- ??????
- ????private?UserModel?um?=?new?UserModel();??
- ??
- ????@Override??
- ????public?String?execute()?{??
- ????????System.out.println("======="+um.toString());??
- ????????try{??
- ????????????userService.save(um);??
- ????//??????userService.save(um);??
- ????????}catch?(Exception?e)?{??
- ????????????System.out.println(e.getMessage());??
- ????????}??
- ??????????
- ????????um.getAddress().setAddress("zhangjavassp");??
- ????????ActionContext.getContext().put("haha",?"hahahhahaa");??
- ????//??userService.save(um);??
- ????????return?"success";??
- ????}??
- ??
- ????public?UserModel?getUm()?{??
- ????????return?um;??
- ????}??
- ??
- ????public?void?setUm(UserModel?um)?{??
- ????????this.um?=?um;??
- ????}??
- ??????
- }??
?
?
2、DAO层代码示例
?
Java代码?
- package?cn.javass.test.dao.impl;??
- ??
- import?cn.javass.framework.ioc.annotation.IService;??
- import?cn.javass.framework.ioc.annotation.Scope;??
- import?cn.javass.framework.orm.impl.BaseDAOImpl;??
- import?cn.javass.test.dao.UserDao;??
- ??
- ??
- @IService(id="userDao",scope=Scope.singleton)??
- public?class?UserDaoImpl?extends?BaseDAOImpl?implements?UserDao{??
- ??????
- }??
?
?
3、服务层代码示例
?
Java代码?
- package?cn.javass.test.service.impl;??
- ??
- import?java.util.List;??
- ??
- import?cn.javass.framework.aop.annotation.IInterceptor;??
- import?cn.javass.framework.aop.transaction.TransactionManagerInterceptor;??
- import?cn.javass.framework.ioc.annotation.IInject;??
- import?cn.javass.framework.ioc.annotation.IService;??
- import?cn.javass.framework.ioc.annotation.Scope;??
- import?cn.javass.test.dao.UserDao;??
- import?cn.javass.test.interceptor.MyInterceptor;??
- import?cn.javass.test.model.UserModel;??
- import?cn.javass.test.service.UserService;??
- ??
- ??
- @IService(id="userService")??
- public?class?UserServiceImpl?implements?UserService{??
- ??????
- ????@IInject(id="userDao")??
- ????private?UserDao?userDao?;??
- ??????
- ??
- ????public?void?setUserDao(UserDao?userDao)?{??
- ????????this.userDao?=?userDao;??
- ????}??
- ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
- ????@Override??
- ????public?boolean?delete(UserModel?um)?{??
- ????????return?this.userDao.delete(um);??
- ????}??
- ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
- ????@Override??
- ????public?List<UserModel>?getAll(UserModel?um)?{??
- ????????return?this.userDao.getAll(um.getClass());??
- ????}??
- ????@IInterceptor(classes={MyInterceptor.class,TransactionManagerInterceptor.class})??
- ????@Override??
- ????public?boolean?save(UserModel?um)?{??
- ????????return?this.userDao.save(um);??
- ????}??
- ??
- }??
?
?
学习期间写的,实现相对简单。