# ditty
**Repository Path**: temper/ditty
## Basic Information
- **Project Name**: ditty
- **Description**: ditty是基于netty、fastjson实现的一款极致简约web restful框架
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 19
- **Created**: 2018-05-27
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ditty
## 项目介绍
ditty是基于netty、fastjson实现的一款极致简约web restful框架。
## 使用说明
### 编写Controller类
```java
@ActionInterceptor(ControllerInterceptor.class)
@ActionMapping(actionKey = "/controller")
public class Controller {
	/**
	 * argName指定参数名可以在web访问的时候使用
	 * actionKey:控制器的actionKey和方法的actionKey确定该方法的唯一路由路径
	 * 不指定方法的actionKey默认为方法名称
	 * @param b
	 * @return
	 */
	@ActionMapping(actionKey = "method1", argNames = { "b" })
	public AxBean method1(BxBean b) {
		System.out.println(getClass().getName() + ".method1(BBean)");
		return new AxBean(1, true, "A", b);
	}
	/**
	 * 本方法的拦截器不仅包含在本方法上声明的拦截器,还包含上层控制器的拦截器、全局拦截器
	 * @param a
	 * @return
	 */
	@ActionInterceptor(MethodInterceptor.class)
	@ActionMapping(argNames = { "a" })
	public int method2(int a) {
		System.out.println(getClass().getName() + ".method2(int)");
		return a;
	}
	/**
	 * 这个方法清除了上层拦截器,保留本方法的拦截器
	 * 通过web访问时,参数名可以用下表代替,比如 “a”->"0"
	 * @param a
	 * @return
	 */
	@ClearActionInterceptor
	@ActionInterceptor(MethodInterceptor.class)
	public String method3(String a) {
		System.out.println(getClass().getName() + ".method3(int)");
		return a;
	}
	/**
	 * 这个方法不会被注册,无法通过web访问
	 */
	@ClearAction
	public void method4() {
		System.out.println(getClass().getName() + ".method4()");
	}
}
```
### 当需要时编写拦截器
```java
public class MethodInterceptor extends AbstractActionIntercptor {
	@Override
	public void interceptor(ActionInvoker invoker) {
		System.out.println(getClass().getName()+":in");
		invoker.inovke();
		System.out.println(getClass().getName()+":out");
	}
}
```
### 启动服务
com.ditty.demo.server.ServerDemo.java
```java
public class ServerDemo {
	public static void main(String[] args) {
		HttpConfiguration.me().getRouters().add(Controller.class);
		ServerFactory.me().getServer().start();
		//自定义服务器启动
		//ServerFactory.me().getServer().start(webDir, port, contextPath);
	}
}
```
### web访问
#### method1
```shell
POST localhost:8090/controller/method1
{
	"b":{"a":1,"b":true,"d":"2018-05-26 16:36:34.039","s":"ss"}
}
```
```json
{
  "returnValue": {
    "a": 1,
    "b": true,
    "bBean": {
      "a": 1,
      "b": true,
      "d": "2018-05-26 16:36:34.039",
      "s": "ss"
    },
    "s": "A"
  }
}
```
#### method2
```shell
POST localhost:8090/controller/method2
{
	"0":1
}
```
```json
{
  "returnValue": 1
}
```
#### method3
```
POST localhost:8090/controller/method3/cc
```
```
{
  "returnValue": "cc"
}
```
*注:可以直接在url路径尾部追加参数,参数分隔符为`-*`
#### 静态资源访问
```
GET localhost:8090/index.html
```
*注:静态资源必须包含`.`*
## 交流
请在下方评论或提issue,我会及时回复。
## 打赏
如果感觉本项目对您有用,打赏是对作者最大的鼓励。
