Menu

Tree [b77661] master v2.0.1 /
 History

HTTPS access


File Date Author Commit
 src 2022-01-02 yuyenews yuyenews [3a53bb] 优化参数校验逻辑,支持范围验证
 .gitignore 2021-04-11 yuyenews yuyenews [01f763] 首次提交
 LICENSE 2021-04-12 yuyenews yuyenews [386f49] 首次提交
 README.md 2022-01-02 yuyenews yuyenews [b77661] 优化参数校验逻辑,支持范围验证
 pom.xml 2022-01-02 yuyenews yuyenews [3a53bb] 优化参数校验逻辑,支持范围验证

Read Me

Magician-Web ·

Magician-Web is the official web component of Magician, which can easily manage Controllers, support interceptors, session management, annotated parameter validation, entity class receiving parameters, etc.

Documentation

https://magician-io.com

Example

Importing dependencies

<!-- This is the jar package build by this project -->
<dependency>
    <groupId>com.github.yuyenews</groupId>
    <artifactId>Magician-Web</artifactId>
    <version>2.0.1</version>
</dependency>

<!-- This is Magician -->
<dependency>
    <groupId>com.github.yuyenews</groupId>
    <artifactId>Magician</artifactId>
    <version>2.0.1</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>

Creating core handlers

@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {

    @Override
    public void request(MagicianRequest magicianRequest, MagicianResponse response) {
        try{
            MagicianWeb.createWeb()
                    .request(magicianRequest);
        } catch (Exception e){
        }
    }
}

Creating Controller

@Route("/demoController")
public class DemoController {

    // You can use entity classes to receive parameters
    @Route(value = "/demo", requestMethod = ReqMethod.POST)
    public DemoVO demo(DemoVO demoVO){
        return demoVO;
    }

    // You can also directly use MagicianRequest to get parameters
    @Route(value = "/demob", requestMethod = ReqMethod.POST)
    public String demob(MagicianRequest request){
        return "ok";
    }

    // Download file
    @Route(value = "/demob", requestMethod = ReqMethod.POST)
    public ResponseInputStream demob(){
        ResponseInputStream responseInputStream = new ResponseInputStream();
        responseInputStream.setName("file name");
        responseInputStream.setBytes(file bytes);
        return responseInputStream;
    }
}

Start HTTP service

Magician.createHttp()
                .scan("handler和controller所在的包名")
                .bind(8080);
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.