|
1 | 1 | package ${package}; |
2 | 2 |
|
3 | 3 | import org.tinystruct.AbstractApplication; |
| 4 | +import org.tinystruct.ApplicationException; |
4 | 5 | import org.tinystruct.system.annotation.Action; |
| 6 | +import org.tinystruct.system.annotation.Action.Mode; |
5 | 7 |
|
6 | | -@Action(value = "", description = "Sample tinystruct application", mode = Action.Mode.CLI) |
7 | 8 | public class Application extends AbstractApplication { |
| 9 | + |
8 | 10 | @Override |
9 | 11 | public void init() { |
10 | | - this.setTemplateRequired(false); |
| 12 | + // Initialization logic (e.g., setting up resources) |
| 13 | + // Note: Do NOT register actions here — use the @Action annotation instead. |
| 14 | + this.setTemplateRequired(false); // Skip .view template lookup if returning data directly |
11 | 15 | } |
12 | 16 |
|
13 | | - @Action(value = "hello", description = "Say hello") |
14 | | - public String sayHello() { |
15 | | - return "Hello from generated tinystruct app!"; |
| 17 | + @Override |
| 18 | + public String version() { |
| 19 | + return "1.0.0"; |
16 | 20 | } |
17 | 21 |
|
18 | | - @Action(value = "hello", description = "Say hello") |
19 | | - public String sayHello(String words) { |
20 | | - return words; |
| 22 | + // Handles: bin/dispatcher hello AND GET /?q=hello |
| 23 | + @Action(value = "hello", description = "Say hello to tinystruct") |
| 24 | + public String sayHello() { |
| 25 | + return "Hello, tinystruct!"; |
21 | 26 | } |
22 | 27 |
|
23 | | - @Action(value = "hello", mode = Mode.HTTP_GET) |
24 | | - public String helloGet() { |
25 | | - return "GET"; |
| 28 | + // Path parameter: GET /?q=greet/James OR bin/dispatcher greet/James |
| 29 | + @Action(value = "greet", description = "Greet a user by name") |
| 30 | + public String greet(String name) { |
| 31 | + return "Hello, " + name + "!"; |
26 | 32 | } |
27 | 33 |
|
28 | | - @Action(value = "hello", mode = Mode.HTTP_POST) |
29 | | - public String helloPost() { |
30 | | - return "POST"; |
| 34 | + // HTTP-only POST handler |
| 35 | + @Action(value = "submit", mode = Mode.HTTP_POST, description = "Handle form submission") |
| 36 | + public String submit() throws ApplicationException { |
| 37 | + // Logic for handling submission |
| 38 | + return "Submitted successfully"; |
31 | 39 | } |
32 | 40 |
|
33 | | - @Action(value = "--help", description = "Print help information") |
| 41 | + // Built-in help command |
| 42 | + @Action(value = "--help", description = "Print help information", mode = Mode.CLI) |
34 | 43 | @Override |
35 | 44 | public String help() { |
36 | 45 | return super.help(); |
37 | 46 | } |
38 | | - |
39 | | - @Override |
40 | | - public String version() { |
41 | | - return ""; |
42 | | - } |
43 | 47 | } |
0 commit comments