Skip to content

Commit bdd64fc

Browse files
committed
Add references to Controller concept
1 parent 9e9b894 commit bdd64fc

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

_posts/2015-03-17-controller.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ public class ControllerDemo {
6868
}
6969
```
7070

71+
**DON'T** forget to add `pippo-controller` module as dependency in your project.
72+
If you use Maven, your `pom.xml` must contains above lines:
73+
74+
```xml
75+
<dependency>
76+
<groupId>ro.pippo</groupId>
77+
<artifactId>pippo-controller</artifactId>
78+
<version>${pippo.version}</version>
79+
</dependency>
80+
81+
```
82+
83+
7184
#### Implementation details
7285

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

_posts/2015-03-17-getting-started.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,14 @@ public class BasicApplication extends ControllerApplication {
143143

144144
@Override
145145
protected void onInit() {
146-
// add controller(s)
147146
addControllers(ContactsController.class); // one instance for EACH request
148-
// or
147+
// OR
149148
addControllers(new ContactsController()); // one instance for ALL requests
150149
}
151150

152151
}
153152
```
153+
154+
For more information about Controllers please see [Controller](controller.html) section.
154155

155156
For a detailed overview please see section [Under the hood](/dev/under-the-hood.html).

index.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ The framework is based on Java Servlet 3.0 and requires Java 8.
2424

2525
**Talk is cheap. Show me the code.**
2626

27-
1) Add some routes in your application
27+
1.1) Routes approach
28+
29+
Add some routes in your application:
2830

2931
```java
3032
public class BasicApplication extends Application {
@@ -73,6 +75,52 @@ public class BasicApplication extends Application {
7375
}
7476
```
7577

78+
1.2) Controllers approach
79+
80+
Define controller(s):
81+
82+
```java
83+
@Path("/contacts")
84+
public class ContactsController extends Controller {
85+
86+
@GET("/?")
87+
public void index() {
88+
List<Contact> contacts = contactService.getContacts();
89+
getResponse().bind("contacts", contacts).render("contacts");
90+
}
91+
92+
@GET("/{id: [0-9]+}")
93+
public void getContact(@Param int id) {
94+
Contact contact = contactService.getContact(id);
95+
getResponse().bind("contact", contact).render(contact);
96+
}
97+
98+
@GET("/text")
99+
@Named("text")
100+
@Produces(Produces.TEXT)
101+
@NoCache
102+
public void complex(@Param int id, @Param String action, @Header String host, @Session String user) {
103+
// do something
104+
}
105+
106+
}
107+
```
108+
109+
Add controller(s) in your application:
110+
111+
```java
112+
public class BasicApplication extends ControllerApplication {
113+
114+
@Override
115+
protected void onInit() {
116+
addControllers(ContactsController.class); // one instance for EACH request
117+
// OR
118+
addControllers(new ContactsController()); // one instance for ALL requests
119+
}
120+
121+
}
122+
```
123+
76124
2) Start your application
77125

78126
```java

0 commit comments

Comments
 (0)