(仅仅是一个仿制Springboot的demo,学习实践而已)
1.使用Netty作为http服务器
2.支持注解@Controller、@RequestMapping等
3.利用maven项目管理
4.简洁的请求数据提取
6.HikariCP连接池
7.IoC设计(反射实现)
8.ORM封装(需大力重构)
9.AOP注解(测试中)
_ _ _ _ _ _ _ _
| | | | |_| |_ _ __ | \ | | ___| |_| |_ _ _
| |_| | __| __| '_ \| \| |/ _ \ __| __| | | |
| _ | |_| |_| |_) | |\ | __/ |_| |_| |_| |
|_| |_|\__|\__| .__/|_| \_|\___|\__|\__|\__, |
|_| Author:saowu |___/
RESTful API
规范@Controller(path = "/index")
public class IndexController {
@RequestMapping(method = RequestMethod.POST, path = "/test")
public String test(Map<String, Object> map) {
return JSONObject.toJSONString(map);
}
}
Http Netty : 2020-05-09 04:34:34 GET -> /
Http Netty : 2020-05-09 04:34:34 GET -> /static/css
Http Netty : 2020-05-09 04:34:34 GET -> /static/js
Http Netty : 2020-05-09 04:34:34 GET -> /static/img
Http Netty : 2020-05-09 04:35:30 POST -> /index/test
application/x-www-form-urlencoded
、multipart/form-data
还是application/json
@RequestMapping(method = RequestMethod.POST, path = "/test")
public String test(Map<String, Object> map) {
return JSONObject.toJSONString(map);
}
@RequestMapping(method = RequestMethod.PUT, path = "/test2")
public String test2(Map<String, Object> map) {
return JSONObject.toJSONString(map);
}
@RequestMapping(method = RequestMethod.GET, path = "/test1")
public String test1(Map<String, Object> map) {
return JSONObject.toJSONString(map);
}
@RequestMapping(method = RequestMethod.DELETE, path = "/test3")
public String test3(Map<String, Object> map) {
return JSONObject.toJSONString(map);
}
@RequestMapping(method = RequestMethod.POST, path = "/upload")
public String uploadfile(Map<String, Object> map) {
HashMap<String, String> fileInfo = new HashMap<>();
for (String key : map.keySet()) {
//获取文件对象并保存
String path = IOUtils.saveFileUpload(key, map.get(key));
fileInfo.put(key, path);
}
return JSONObject.toJSONString(fileInfo);
}
@Component
public class TestService {
@Autowired
private TestDao testDao;
public List<Files> selectAll() {
List<Files> filesList = testDao.selectAll();
return filesList;
}
}
jdbcUrl=jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driverClassName=com.mysql.jdbc.Driver
dataSource.user=root
dataSource.password=123456
dataSource.connectionTimeout=30000
dataSource.idleTimeout=600000
dataSource.maxLifetime=1800000
dataSource.maximumPoolSize=30
@Table
public class Files {
@Column(name = "id")
private String id;
@Column(name = "name")
private String name;
@Column(name = "path")
private String path;
@Column(name = "type")
private String type;
/*Getter、Setter*/
}
@Repository
public class TestDao {
@Autowired
private PoolUtils poolUtils;
public List<Files> selectFiles(Map<String, Object> map) {
List<Files> filesList = ORMUtils.executeQuery(poolUtils, Files.class, map);
return filesList;
}
public boolean updateFiles(Files files) {
int i = ORMUtils.executeUpdate(poolUtils, Files.class, files);
return i > 0;
}
public boolean insertFiles(Files files) {
int i = ORMUtils.executeInsert(poolUtils, Files.class, files);
return i > 0;
}
public boolean deleteFiles(Map<String, Object> map) {
int i = ORMUtils.executeDelete(poolUtils, Files.class, map);
return i > 0;
}
}
.
├── README.md
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── org
│ │ └── saowu
│ │ ├── Application.java
│ │ ├── controller
│ │ │ └── TestController.java
│ │ ├── core
│ │ │ ├── annotation
│ │ │ │ ├── Autowired.java
│ │ │ │ ├── Column.java
│ │ │ │ ├── Component.java
│ │ │ │ ├── Controller.java
│ │ │ │ ├── Entity.java
│ │ │ │ ├── Repository.java
│ │ │ │ ├── RequestMapping.java
│ │ │ │ └── Service.java
│ │ │ ├── banner
│ │ │ ├── config
│ │ │ │ └── ApplicationContext.java
│ │ │ ├── pojo
│ │ │ │ ├── RequestMethod.java
│ │ │ │ ├── RouteInfo.java
│ │ │ │ ├── SCSS.java
│ │ │ │ ├── SIMG.java
│ │ │ │ ├── SJS.java
│ │ │ │ └── Template.java
│ │ │ ├── server
│ │ │ │ ├── BootServer.java
│ │ │ │ ├── HttpRequestHandler.java
│ │ │ │ └── InitCenter.java
│ │ │ └── utils
│ │ │ ├── AnnotationUtils.java
│ │ │ ├── HttpRequestUtils.java
│ │ │ ├── IOUtils.java
│ │ │ ├── PoolUtils.java
│ │ │ ├── ReflexUtils.java
│ │ │ ├── ResponseUtils.java
│ │ │ └── ResultSetUtils.java
│ │ ├── dao
│ │ │ └── TestDao.java
│ │ ├── entity
│ │ │ └── Files.java
│ │ └── service
│ │ └── TestService.java
│ └── resources
│ ├── hikari.properties
│ ├── static
│ │ ├── css
│ │ │ └── index.css
│ │ ├── img
│ │ │ └── picture.png
│ │ └── js
│ │ └── index.js
│ ├── templates
│ │ └── index.html
│ └── upload
└── test
└── java
└── org
└── saowu
└── AppTest.java
26 directories, 39 files
siege -c 200 -r 100 http://127.0.0.1:9000/test1
{ "transactions": 19855,
"availability": 99.28,
"elapsed_time": 41.73,
"data_transferred": 0.04,
"response_time": 0.31,
"transaction_rate": 475.80,
"throughput": 0.00,
"concurrency": 149.54,
"successful_transactions": 19855,
"failed_transactions": 145,
"longest_transaction": 19.77,
"shortest_transaction": 0.00
}
那当然是我太菜了,不是netty的问题