You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2015-03-17-controller.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,7 +148,53 @@ If you use Maven, your `pom.xml` must contains above lines:
148
148
149
149
```
150
150
151
+
#### Parameter name
151
152
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
+
152
198
#### Implementation details
153
199
154
200
Advanced features (Extractor, Interceptor, ...) and technical aspects are presented in details [here](https://github.com/decebals/pippo/pull/341).
0 commit comments