Nutz-Mvc Manual

Main Module - block - entry function


The main module

Any class can be used as a master module, if you configure it in web.xml, this design is to facilitate non-JSP / Servlet web server consolidation Nutz.mvc marked frame.

In the main module, you can declare the following notes:


@Modules - all sub-module declaration applications

Designated sub-module

@Modules({ UserModule.class, PetModule.class})
public class MainModule {
    ...

Adding automatic scanning

//模块类自动扫描,添加这行注解nutz将自动扫描主模块所在包下所有的子模块以及入口函数(带有@At注解)
@Modules(scanPackage = true) //1.r.58开始默认就是true
public class MainModule {
    ...

All classes at the main module to automatically search packet type, Abc.class, Xyz.class where (including sub-packet), if there is more than one class includes entry point to be considered is the module type.


@IocBy - Ioc container settings used

Obtaining declared Ioc container details, please refer to  working with Ioc container  .


@SetupBy - additional processing at launch and shut down

Throughout the application to start or shut down , you want to do some additional processing work, you can achieve a org.nutz.mvc.Setup interface and configure it on the main module

@SetupBy(MyAppSetup.class)
public class MainModule {
    ...

E.g

public class MainSetup implements Setup {

	public void init(NutConfig nc) {
		Ioc ioc = nc.getIoc();
		Dao dao = ioc.get(Dao.class);
		Daos.createTablesInPackage(dao, "net.wendal.nutzDemo", false);

		// 初始化默认根用户
		if (dao.count(User.class) == 0) {
			User user = new User();
			user.setName("admin");
			user.setPassword("123456");
			user.setCreateTime(new Date());
			user.setUpdateTime(new Date());
			dao.insert(user);
		}
	}

	public void destroy(NutConfig nc) {
		// webapp销毁之前执行的逻辑
		// 这个时候依然可以从nc取出ioc, 然后取出需要的ioc 对象进行操作
	}

}

 


Sub-module

Any class can be used as sub-modules, provided by the  annotation @Modules  declaration to the main module on to

In sub-modules, you can declare


Entry function

Any sub-module function, as long as the public, and not static, and can be used as a method of the entry function are denoted by numerals entry function annotation thereon  @At

On entry function, annotation can be declared as follows:

@At - entry function corresponding URL

Only mark this annotation function be considered entry function , for example,

@At("/my/abc")
public void someFunc(){
    ...

You can also declare more than one URL for the function

@At({"/my/abc", "/my/xyz"})
public void someFunc(){
    ...

@Ok - Success view

Statement view successful entry function, i.e., if the entry point is normally performed, by this view will be rendered to the function returns the HTTP response. Of course, if your function returns is a direct view of the object, then it will not use the success view (but you return to the view object) to render the HTTP response in detail, please refer to  view  a

@Fail - failure view

Declares the failure of view of the inlet function that throws an exception if the entry will be rendered by the view exception to the HTTP response in detail, please refer to  view  a

@AdaptBy - HTTP parameter adaptation mode

The process HTTP request parameters into the parameters of your current entry function is called  adaptation , the statement notes that this adapter. If you do not specify this annotation, the default will be used to adapt PairAdaptor HTTP request parameters. A detailed description, see the adapter  a

@Filter - Filter

See details  filter  section

@Encoding - Input Output Coding

Defined input and output encoding HTTP request, the annotation will usually defined in the  main module  above, the entire application in order to ensure a unified input-output setting

If you do not define default, Nutz.Mvc will use  UTF-8  coding as the input and output

@Encoding(input="UTF-8",output="UTF-8")

 


view


What is a view?

Tasks view of the inlet is the return value of the function (a Java object) rendered to the HTTP response stream.

Now comes the main view has Nutz.Mvc

  • JSP - JSP template using the output of the page
  • Redirect - redirects the client
  • Forward - server transfer
  • Json - object output string into Json
  • void - do nothing
  • Raw - binary output, the output image, file downloads, etc.

Of course, you can also need to develop your own view based on the implementation class, customize your own view is also very simple, see article  # customize their view of  a.


Getting Started:

 

Published 25 original articles · won praise 6 · views 7546

Guess you like

Origin blog.csdn.net/B_G_boy/article/details/103362226