Giter VIP home page Giter VIP logo

today-framework-old's Introduction

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

today-framework-old's People

Contributors

codacy-badger avatar dependabot[bot] avatar i1619khz avatar taketoday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

today-framework-old's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.