3 Star 5 Fork 1

TODAY / TODAY Framework Old

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 5.87 KB
一键复制 编辑 原始数据 按行查看 历史
TODAY 提交于 2021-06-27 22:05 . :memo:更新文档

TODAY Framework

Java8 GPLv3 Author Codacy Badge

安装

<dependency>
  <groupId>cn.taketoday</groupId>
  <artifactId>today-framework</artifactId>
  <version>1.0.1.RELEASE</version>
</dependency>

开始

只需要

@RestController
public class DemoApplication {

  @GET("/index/{q}")
  public String index(String q) {
    return q;
  }

  public static void main(String[] args) {
    WebApplication.run(DemoApplication.class, args);
  }
}

在 Netty 里运行

@Slf4j
@RestController // rest 控制器
@RestControllerAdvice
@Import(NettyApplication.AppConfig.class) // 导入配置
public class NettyApplication {

  public static void main(String[] args) {
    WebApplication.runReactive(NettyApplication.class, args);
  }

  @GET("/index")
  public String index() {
    return "Hello";
  }

  @GET("/body/{name}/{age}")
  public Body index(String name, int age) {
    return new Body(name, age);
  }

  @GET("/publish-event")
  public void index(String name, @Autowired ApplicationEventPublisher publisher) {
    publisher.publishEvent(new MyEvent(name));
  }

  @GET("/request-context")
  public String context(RequestContext context) {
    final String requestURL = context.requestURL();
    final String queryString = context.queryString();
    System.out.println(requestURL);
    System.out.println(queryString);

    return queryString;
  }

  @Getter
  static class Body {
    final String name;
    final int age;

    Body(String name, int age) {
      this.name = name;
      this.age = age;
    }
  }

  @Configuration
  @EnableNettyHandling
  @EnableMethodEventDriven
  static class AppConfig {

    @EventListener(MyEvent.class)
    public void event(MyEvent event) {
      log.info("event :{}", event);
    }
  }

  @ToString
  static class MyEvent {
    final String name;

    MyEvent(String name) {
      this.name = name;
    }
  }

  @ExceptionHandler(Throwable.class)
  public void throwable(Throwable throwable) {
    throwable.printStackTrace();
  }

}

在 Servlet 容器里运行

@Slf4j
@Configuration
@RequestMapping
@EnableDefaultMybatis
@EnableRedissonCaching
@EnableTomcatHandling
@ComponentScan("cn.taketoday.blog")
@PropertiesSource("classpath:info.properties")
@MultipartConfig(maxFileSize = 10240000, fileSizeThreshold = 1000000000, maxRequestSize = 1024000000)
public class TestApplication implements WebMvcConfiguration, ApplicationListener<ContextStartedEvent> {

  public static void main(String[] args) {
    WebApplication.run(TestApplication.class, args);
  }

  @GET("index/{q}")
  public String index(String q) {
    return q;
  }

  @Singleton
  @Profile("prod")
  public ResourceHandlerRegistry prodResourceMappingRegistry() {

    final ResourceHandlerRegistry registry = new ResourceHandlerRegistry();

    registry.addResourceMapping(LoginInterceptor.class)//
            .setPathPatterns("/assets/admin/**")//
            .setOrder(Ordered.HIGHEST_PRECEDENCE)//
            .addLocations("/assets/admin/");

    return registry;
  }

  @Singleton
  @Profile("dev")
  public ResourceHandlerRegistry devRsourceMappingRegistry(@Env("site.uploadPath") String upload,
                                                           @Env("site.assetsPath") String assetsPath) //
  {
    final ResourceHandlerRegistry registry = new ResourceHandlerRegistry();

    registry.addResourceMapping("/assets/**")//
            .addLocations(assetsPath);

    registry.addResourceMapping("/upload/**")//
            .addLocations(upload);

    registry.addResourceMapping("/logo.png")//
            .addLocations("file:///D:/dev/www.yhj.com/webapps/assets/images/logo.png");

    registry.addResourceMapping("/favicon.ico")//
            .addLocations("classpath:/favicon.ico");

    return registry;
  }

  @Override
  public void onApplicationEvent(ContextStartedEvent event) {
    log.info("----------------Application Started------------------");
  }
}

🙏 鸣谢

本项目的诞生离不开以下开源项目:

  • Slf4j: Simple Logging Facade for Java
  • EL: Java Unified Expression Language
  • Lombok: Very spicy additions to the Java programming language
  • FastJSON: A fast JSON parser/generator for Java
  • Freemarker: Apache Freemarker
  • Apache Commons FileUpload: Apache Commons FileUpload
  • Netty: Netty project - an event-driven asynchronous network application framework
  • Jetty: Eclipse Jetty® - Web Container
  • Tomcat: Apache Tomcat
  • Undertow: High performance non-blocking webserver
  • Today Web: A Java library for building web applications
  • Today Context: A Java library for dependency injection and aspect oriented programing
  • JLHTTP: Java Lightweight HTTP Server (Web Server)

📄 开源协议

请查看 GNU GENERAL PUBLIC LICENSE

Java
1
https://gitee.com/I-TAKE-TODAY/today-framework-old.git
git@gitee.com:I-TAKE-TODAY/today-framework-old.git
I-TAKE-TODAY
today-framework-old
TODAY Framework Old
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891