IoC容器+Web层框架+ORM框架的实现
一个IoC容器+Web层框架+ORM框架的简单实现(适用于学习用) 类似于SSH实现。
在学习期间写的,实现相对简单。欢迎下载。
涉及技术点:
反射、注解、配置文件、动态代理
实现了:
IoC AOP Web层框架 ORM框架 。
1、Web层代码示例:
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层代码示例
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、服务层代码示例
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); } }
学习期间写的,实现相对简单。
相关推荐
itjavashuai 2020-07-28
smalllove 2020-07-27
willluckysmile 2020-06-29
TiDBPingCAP 2020-06-21
丽丽 2020-06-11
shenxiuwen 2020-06-10
willluckysmile 2020-06-10
MrFuWen 2020-06-09
yuanye0 2020-06-08
whbing 2020-05-19
yuanye0 2020-05-14
kong000dao0 2020-05-10
方志朋 2020-05-08
somyjun 2020-05-01
suixinsuoyu 2020-04-29
咻pur慢 2020-04-22
tianxiaolu 2020-04-06
吾日五省我身 2020-03-28