Magician-Route is the official web component of Magician, which was developed from Magician-Web, mainly by removing the reflection inside, sacrificing a bit of ease of use and putting the focus on performance.
<!-- This is the jar package build by this project -->
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician-Route</artifactId>
<version>1.0.0</version>
</dependency>
<!-- This is Magician -->
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>2.0.7</version>
</dependency>
<!-- This is the log package, which supports any package that can be bridged with slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
</dependency>
@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {
@Override
public void request(MagicianRequest magicianRequest, MagicianResponse response) {
try{
MagicianRoute.request(magicianRequest);
} catch (Exception e){
}
}
}
@Route
public class DemoRoute implements MagicianInitRoute {
@Override
public void initRoute(MagicianRouteCreate routeCreate) {
routeCreate.get("/demo/getForm", request -> {
DemoVO demoVO = ConversionUtil.conversionAndVerification(request, DemoVO.class);
System.out.println(request.getParam("name") + "---" + demoVO.getName());
return "{\"msg\":\"hello login\"}";
});
routeCreate.post("/demo/json", request -> {
DemoVO demoVO = ConversionUtil.conversionAndVerification(request, DemoVO.class);
System.out.println(request.getJsonParam() + "---" + demoVO.getName());
return "{\"msg\":\"hello json\"}";
});
}
}
Magician.createHttp()
.scan("Packages to be scanned")
.bind(8080);