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-getting-started.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ order: 10
9
9
We provide a pippo-demo module that contains many demo applications (submodules): pippo-demo-basic and pippo-demo-crud are some.
10
10
For a list with all demo please see [Demo](demo.html) section.
11
11
12
+
#### Routes approach
13
+
12
14
For [pippo-demo-basic]({{ site.demourl }}/pippo-demo-basic) you have two java files: [BasicDemo.java]({{ site.demourl }}/pippo-demo-basic/src/main/java/ro/pippo/demo/basic/BasicDemo.java) and [BasicApplication.java]({{ site.demourl }}/pippo-demo-basic/src/main/java/ro/pippo/demo/basic/BasicApplication.java)
13
15
We split our application in two parts for a better readability.
14
16
@@ -99,4 +101,55 @@ Open your internet browser and check the routes declared in Application:
99
101
- `http://localhost:8338/negotiate`
100
102
- `http://localhost:8338/template`
101
103
104
+
#### Controllers approach
105
+
106
+
Another approach to handling a request and producing a response is using Controllers. After routing has determined what controller to use, an action method will be invoked.
107
+
In Pippo, controllers are instances of [Controller]({{ site.codeurl }}/pippo-controller-parent/pippo-controller/src/main/java/ro/pippo/controller/Controller.java).
108
+
109
+
Defining a new controller is simple:
110
+
111
+
```java
112
+
@Path("/contacts")
113
+
public class ContactsController extends Controller {
public void complex(@Param int id, @Param String action, @Header String host, @Session String user) {
132
+
// do something
133
+
}
134
+
135
+
}
136
+
```
137
+
138
+
Methods attached to the controller (for example `index` from above snippet) are known as action methods. When Pippo receives a request, it will create a new instance of the controller and call the appropriate action method.
139
+
You can register a controller's action in application with a simple line:
0 commit comments