1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| registerRequestMapping( StudentApi, "/students/{id}", RequestMethod.PUT, [ new PathVariable("id", DataType.STRING, "学生ID"), new RequestBody("student", DataType.OBJECT, UpdateStudentDto, "学生"), ], [ new Response(HttpStatusCode.OK, DataType.STRING, "ok"), new Response(HttpStatusCode.INTERNAL_SERVER_ERROR, DataType.STRING, "内部错误"), new Response(HttpStatusCode.NOT_FOUND, DataType.STRING, "学生未找到"), ], "修改学生"); route.put("/:id", (req, res, next) => { const input = req.body; const id = req.params.id; if (!id) { res.status(HttpStatusCode.INTERNAL_SERVER_ERROR); res.json("学生ID不能为空"); return; }
if (lodash.findIndex(this.students, (x) => x.uuid === id) < 0) { res.status(HttpStatusCode.NOT_FOUND); res.json(`未能找到学生`); return; }
const student = new Student(); student.uuid = id; student.name = input.name; student.age = input.age; this.modifyStudent(student); res.json("ok"); });
|