public class Blade extends Object
The Blade is the core operating class of the framework, which can be used to register routes, modify the template engine, set the file list display, static resource directory, and so on.
构造器和说明 |
---|
Blade() |
限定符和类型 | 方法和说明 |
---|---|
Blade |
addStatics(String... folders)
Add multiple static resource file
the default provides the static, upload
|
Blade |
after(String path,
RouteHandler handler)
Add a after route to routes, the before route will be executed after matching route
|
Blade |
appName(String appName)
Set in the name of the app blade application
|
Blade |
await()
Await web server started
|
Blade |
before(String path,
RouteHandler handler)
Add a before route to routes, the before route will be executed before matching route
|
Class<?> |
bootClass() |
Blade |
bootConf(String bootConf)
Set to start blade configuration file by default
Boot config properties file in classpath directory.
|
Blade |
delete(String path,
RouteHandler handler)
Add a delete route to routes
|
boolean |
devMode()
Get current is developer mode
|
Blade |
devMode(boolean devMode)
Whether encoding setting mode for developers
The default mode is developers
|
Blade |
disableSession()
Disable session, default is open
|
Blade |
enableCors(boolean enableCors)
Set whether to enable cors
|
Environment |
environment() |
Blade |
environment(String key,
Object value)
Set the environment variable for global use here
|
Blade |
event(EventType eventType,
EventListener eventListener)
Add a event listener
When the trigger event is executed eventListener
|
EventManager |
eventManager()
Get EventManager
|
ExceptionHandler |
exceptionHandler()
Get ExceptionHandler
|
Blade |
exceptionHandler(ExceptionHandler exceptionHandler)
Set ExceptionHandler, when you need a custom exception handling
|
Blade |
get(String path,
RouteHandler handler)
Add a get route to routes
|
Object |
getBean(Class<?> cls)
Get ioc bean
|
Set<String> |
getStatics()
Get blade statics list.
|
Blade |
gzip(boolean gzipEnable)
Set whether open gzip, default disabled
|
Ioc |
ioc()
Get blade ioc container, default is SimpleIoc implement.
|
Blade |
listen(int port)
Set to start the web server to monitor port, the default is 9000
|
Blade |
listen(String address,
int port)
Set to start the web server to listen the IP address and port
The default will listen 0.0.0.0:9000
|
static Blade |
me()
Give your blade instance, from then on will get the energy
|
List<WebHook> |
middleware()
Get middleware list
|
Blade |
onStarted(BeanProcessor processor)
Event on started
|
Blade |
post(String path,
RouteHandler handler)
Add a post route to routes
|
List<BeanProcessor> |
processors()
Get processors
|
Blade |
put(String path,
RouteHandler handler)
Add a put route to routes
|
Blade |
register(Class<?> cls)
Register bean to ioc container
|
Blade |
register(Object bean)
Register bean to ioc container
|
RouteMatcher |
routeMatcher()
Get RouteMatcher
|
Set<String> |
scanPackages()
Get scan the package set.
|
Blade |
scanPackages(String... packages)
When set to start blade scan packages
|
SessionManager |
sessionManager()
Get SessionManager
|
Class<? extends Session> |
sessionType()
Get session implements Class Type
|
Blade |
sessionType(Class<? extends Session> sessionImplType)
Set session implements Class Type, e.g: RedisSession
|
Blade |
showFileList(boolean fileList)
Set whether to show the file directory, default doesn't show
|
Blade |
start()
Start blade application.
|
Blade |
start(Class<?> mainCls,
String... args)
Start blade application
|
Blade |
start(Class<?> bootClass,
String address,
int port,
String... args)
Start the blade web server
|
void |
stop()
Stop current blade application
Will stop synchronization waiting netty service
|
TemplateEngine |
templateEngine()
Get TemplateEngine, default is DefaultEngine
|
Blade |
templateEngine(TemplateEngine templateEngine)
Setting blade mvc default templateEngine
|
Blade |
use(WebHook... middleware)
The use of multiple middleware, if any
|
public static Blade me()
public Ioc ioc()
IOC container will help you hosting Bean or component, it is actually a Map inside. In the blade in a single way to make objects reuse, you can save resources, to avoid the terrible memory leak
public Blade get(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade post(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade put(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade delete(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade before(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade after(@NonNull String path, @NonNull RouteHandler handler)
path
- your route pathhandler
- route implementpublic Blade templateEngine(@NonNull TemplateEngine templateEngine)
templateEngine
- TemplateEngine objectpublic TemplateEngine templateEngine()
public RouteMatcher routeMatcher()
public Blade register(@NonNull Object bean)
bean
- bean objectpublic Blade register(@NonNull Class<?> cls)
cls
- bean class, the class must provide a no args constructorpublic Blade addStatics(@NonNull String... folders)
folders
- static resource directorypublic Blade showFileList(boolean fileList)
fileList
- show the file directorypublic Blade gzip(boolean gzipEnable)
gzipEnable
- enabled gzippublic Object getBean(@NonNull Class<?> cls)
cls
- bean class typepublic ExceptionHandler exceptionHandler()
public Blade exceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler
- your ExceptionHandler instancepublic boolean devMode()
public Blade devMode(boolean devMode)
devMode
- developer modepublic Class<?> bootClass()
public Blade enableCors(boolean enableCors)
enableCors
- enable corspublic Set<String> getStatics()
public Blade scanPackages(@NonNull String... packages)
packages
- package namepublic Blade bootConf(@NonNull String bootConf)
Without setting will read the classpath -> app.properties
bootConf
- boot config file namepublic Blade environment(@NonNull String key, @NonNull Object value)
key
- environment keyvalue
- environment valuepublic Environment environment()
public Blade listen(int port)
port
- web server portpublic Blade listen(@NonNull String address, int port)
address
- ip addressport
- web server portpublic Blade use(@NonNull WebHook... middleware)
middleware
- middleware object arraypublic Blade appName(@NonNull String appName)
appName
- application namepublic Blade event(@NonNull EventType eventType, @NonNull EventListener eventListener)
eventType
- event typeeventListener
- event listenerpublic Class<? extends Session> sessionType()
public Blade sessionType(Class<? extends Session> sessionImplType)
sessionImplType
- Session Type implementpublic Blade onStarted(@NonNull BeanProcessor processor)
processor
- bean processorpublic List<BeanProcessor> processors()
public EventManager eventManager()
public SessionManager sessionManager()
public Blade disableSession()
public Blade start()
When all the routing in the main function of situations you can use, Otherwise please do not call this method.
public Blade start(Class<?> mainCls, String... args)
mainCls
- main Class, the main class bag is basic packageargs
- command argumentspublic Blade start(Class<?> bootClass, @NonNull String address, int port, String... args)
bootClass
- Start the boot class, used to scan the class in all of the packagesaddress
- web server bind ip addressport
- web server bind portargs
- launch parameterspublic Blade await()
public void stop()
Will stop synchronization waiting netty service
Copyright © 2017. All rights reserved.