Skip to content

Commit a613084

Browse files
committed
Improve Controller section
1 parent f810acf commit a613084

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

_posts/2015-03-17-controller.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,53 @@ If you use Maven, your `pom.xml` must contains above lines:
148148

149149
```
150150

151+
#### Parameter name
151152

153+
The Controller module may depend on the `-parameters` flag of the Java 8 javac compiler. This flag embeds the names of method parameters in the generated .class files.
154+
155+
By default Java 8 does not compile with this flag set so you must specify javac compiler arguments for Maven and your IDE.
156+
```
157+
<build>
158+
<plugins>
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-compiler-plugin</artifactId>
162+
<configuration>
163+
<source>1.8</source>
164+
<target>1.8</target>
165+
<compilerArguments>
166+
<parameters/>
167+
</compilerArguments>
168+
</configuration>
169+
</plugin>
170+
</plugins>
171+
</build>
172+
```
173+
174+
So, if you you compile with `-parameters` flag you can define the controller method like:
175+
```java
176+
void invoice(@Param orderId) { ... }
177+
```
178+
179+
instead of:
180+
```java
181+
void invoice(@Param("orderId") orderId) { ... }
182+
```
183+
184+
If you use the first variant without `-parameters` flag on compile, you will receive an exception like:
185+
```java
186+
ro.pippo.core.PippoRuntimeException: Method 'acme.controller.MyController::invoice' parameter 0 does not specify a name!
187+
at ro.pippo.controller.extractor.ParamExtractor.getParameterName(ParamExtractor.java:69)
188+
at ro.pippo.controller.extractor.ParamExtractor.extract(ParamExtractor.java:44)
189+
at ro.pippo.controller.ControllerRouteHandler.prepareMethodParameters(ControllerRouteHandler.java:388)
190+
at ro.pippo.controller.ControllerRouteHandler.handle(ControllerRouteHandler.java:120)
191+
at ro.pippo.core.route.DefaultRouteContext.handleRoute(DefaultRouteContext.java:394)
192+
at ro.pippo.core.route.DefaultRouteContext.next(DefaultRouteContext.java:276)
193+
at ro.pippo.core.route.RouteDispatcher.onRouteDispatch(RouteDispatcher.java:153)
194+
at ro.pippo.core.route.RouteDispatcher.dispatch(RouteDispatcher.java:101)
195+
at ro.pippo.core.PippoFilter.processRequest(PippoFilter.java:179)
196+
```
197+
152198
#### Implementation details
153199

154200
Advanced features (Extractor, Interceptor, ...) and technical aspects are presented in details [here](https://github.com/decebals/pippo/pull/341).

0 commit comments

Comments
 (0)