Skip to content

exacode/spring-webmvc-processor

Repository files navigation

Annotation processor for SpringWebMvc Controllers

Flattr this! Build Status

An annotation processor for spring-webmvc controllers.

What it does?

  • generates meta model for all HTTP GET @RequestMappings declared inside classes annotated with @Controller
  • enables creation of stringless routings

How to configure?

Maven

Take look on an example project.

In order to use this processor add repository location into your pom.xml and add processor dependency.

	</dependencies>
		<dependency>
			<groupId>net.exacode.spring.web</groupId>
			<artifactId>spring-webmvc-processor-shared</artifactId>
			<version>${version.spring-webmvc-processor}</version>
		</dependency>
	</dependencies>

Although there is also a second configuration option, the first one is more IDE friendly.

Usage example

Using this annotation processor and spring-webmvc you can create stringless queries like:

	@Controller
	public class UserController {

		@RequestMapping(value = "/users")
		public String getUsers() {
			return "users.ftl";
		}

	}

	@Controller
	public class SomeFormController {

		@RequestMapping(value = "/some-form", method = RequestMethod.POST)
		public String submitSomeForm() {
			// Some form processing...
			return UserController_.getUsers().mvc().redirect(); // generates: "redirect:/users"
		}
	
	}

This annotation processor handles also parameters of every type (@RequestParam, @PathVariable, @MatrixParameter) and both required and optional:

	@Controller
	public class UserController {

		@RequestMapping(value = "/users/{userId}/{resource}")
		public void getUserResource(@PathVariable String userId, @PathVariable String resource) {
			// ...
		}

		// metamodel: UserController_.getUserResource("user123", "image").mvc().redirect(); 
		// generates: "redirect:/users/user123/image"
		// Note that all required parameters are also required by generated meta controller.

		@RequestMapping(value = "/users/{userId}")
		public void getUser(@PathVariable String userId, @RequestParameter(required=false) String query) {
			// ...
		}

		// metamodel: UserController_.getUsers("user123").query("some-value").mvc().redirect(); 
		// generates: "redirect:/users/user123?query=some-value"
		// Note that all optional parameters are chained therefore also optional in meta controller.
	
	}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages