|
6 | 6 | import com.bj58.argo.annotations.POST; |
7 | 7 | import com.bj58.argo.annotations.Path; |
8 | 8 | import com.bj58.argo.client.ClientContext; |
| 9 | +import com.bj58.argo.client.Upload; |
9 | 10 | import com.bj58.argo.controller.AbstractController; |
10 | 11 | import com.google.common.base.Preconditions; |
11 | 12 | import com.google.common.base.Strings; |
12 | | -import com.sun.jndi.toolkit.url.Uri; |
13 | 13 |
|
14 | 14 | // 类的命名受 GroupConvetionAnnotation.controllerPattern约束 |
15 | 15 | public class HomeController extends AbstractController { |
16 | 16 |
|
17 | | - @Path("/") |
| 17 | + @Path("") |
18 | 18 | public ActionResult home() { |
19 | | - Uri uri; |
| 19 | + System.out.println(1); |
20 | 20 | return view("index"); // velocity模板是 /src/main/java/resources/views/index.html |
21 | 21 | } |
22 | 22 |
|
@@ -50,4 +50,48 @@ public ActionResult postForm() { |
50 | 50 | return view("post"); // resources/views/post.html velocity模板 |
51 | 51 |
|
52 | 52 | } |
| 53 | + |
| 54 | + /** |
| 55 | + * |
| 56 | + * 处理文件上传 |
| 57 | + * |
| 58 | + */ |
| 59 | + @Path("post-upload.html") |
| 60 | + @POST // 只处理post的请求 |
| 61 | + public ActionResult postUpload() { |
| 62 | + |
| 63 | + BeatContext beat = beat(); |
| 64 | + |
| 65 | + ClientContext client = beat.getClient(); |
| 66 | + |
| 67 | + Preconditions.checkState(Strings.isNullOrEmpty(client.form("company"))); |
| 68 | + Preconditions.checkState(Strings.isNullOrEmpty(client.form("address"))); |
| 69 | + Preconditions.checkState(Strings.isNullOrEmpty(client.form("file"))); |
| 70 | + |
| 71 | + client.queryString("name"); |
| 72 | + |
| 73 | + Preconditions.checkState(Strings.isNullOrEmpty(client.queryString("name"))); |
| 74 | + Preconditions.checkState(Strings.isNullOrEmpty(client.queryString("phone"))); |
| 75 | + Preconditions.checkState(Strings.isNullOrEmpty(client.queryString("submit"))); |
| 76 | + Preconditions.checkState(Strings.isNullOrEmpty(client.queryString("file"))); |
| 77 | + |
| 78 | + |
| 79 | + Upload upload = client.getUpload("file"); |
| 80 | + |
| 81 | + |
| 82 | + beat.getModel() |
| 83 | + .add("company", client.queryString("company")) |
| 84 | + .add("address", client.queryString("address")) |
| 85 | + |
| 86 | + .add("name", client.form("name")) |
| 87 | + .add("phone", client.form("phone")) |
| 88 | + .add("submit", client.form("submit")) |
| 89 | + |
| 90 | + .add("upload", upload); |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + return view("post-upload"); // resources/views/post-upload.html velocity模板 |
| 95 | + |
| 96 | + } |
53 | 97 | } |
0 commit comments