NettyMVC is a lightweight IOC, MVC framework which based on netty http procotol.
NettyMVC 是一个基于 Netty http 协议的轻量级高性能 IOC,MVC 框架。
- NettyMVC is an MVC framework that implements the relevant functionality of the IOC container.
- Support MVC annotations such as @controller, @requestparam, @requestmapping, etc.
- Support @ Service, @ Repositry, @autowired IOC annotation.
- URI route resolution, parameter mapping.
- Request supports a variety of parameter types, including basic data types, List, Array, Map, and so on.
- NettyMVC 是一个 MVC 框架,它实现了 IOC 容器的相关功能。
- 支持 @Controller,@RequestParam,@RequestMapping 等 MVC 注解。
- 支持 @Service,@Repositry,@Autowired 等 IOC 注解。
- URI 路由解析,参数映射。
- Request 中支持多种参数类型,包括基本数据类型,List,Array,Map等等。
- 在项目中引入 netty-mvc-core 模块。
- 在 Maven 项目中的 resources 文件夹下创建 applicationContext.xml, 用来配置 IOC 的包扫描路径。
<?xml version="1.0" encoding="UTF-8"?> <beans> <package-scan component-scan="org.test.demo" /> </beans>
- @Controller 对应控制层注解,@Service 对应服务层注解,@Respostry 对应持有层注解, @Autowired 做自动注入,@RequestMapping 做路由,
@RequestParam 做参数映射。
@Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @RequestMapping("/getUser") public FullHttpResponse getUserById(FullHttpRequest request,@RequestParam("userId") int id,@RequestParam("name") String name){ String res = userService.getUser(id); return HttpUtil.constructText(res); } }
@Service("userService") public class UserServiceImpl implements UserService { @Autowired("userDao") private UserDao userDao; @Override public String getUser(int id) { return userDao.get(id); } }
@Repository public class UserDao { public String get(int id){ if(id == 1){ return "paul"; }else{ return "wang"; } } }
- 目前方法参数与 request 匹配时必须使用 RequestParam 注解。
- 对于没有实现接口的类如果注入时,@Autowired 注解必须指定实例名称。
以上两个问题因为目前无法获取参数名(不是参数类型),下一步将会进行 fix。