🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
我们首先使用astah将类图自动转化为JAVA代码,并添加SET/GET方法。 ![https://box.kancloud.cn/fd26cb4eb94fe0c112f95e69b97d977c_1000x634.png](https://box.kancloud.cn/fd26cb4eb94fe0c112f95e69b97d977c_1000x634.png) 初始代码如下: ``` package com.mengyunzhi.javaee.action.klass; import com.mengyunzhi.javaee.action.Action; public class UpdateAction extends Action { private static final long serialVersionUID = 1L; private Long klassId; private String name; private Long teacherId; public Long getKlassId() { return klassId; } public void setKlassId(Long klassId) { this.klassId = klassId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Long getTeacherId() { return teacherId; } public void setTeacherId(Long teacherId) { this.teacherId = teacherId; } public String execute() { return SUCCESS; } } ``` 然后根据时序图,进行数据转发的代码开发. ![https://box.kancloud.cn/f11526a6e77c87f5e0ee4ff48d04405a_1360x552.png](https://box.kancloud.cn/f11526a6e77c87f5e0ee4ff48d04405a_1360x552.png) ``` public String execute() { KlassServer.updateKlassByIdNameTeacherId(klassId, name, teacherId); return SUCCESS; } ``` # 测试 ## URL: http://127.0.0.1:8080/javaee/klass.Update.json ## 请求格式 json ## HTTP请求方式 POST ## 请求数据 { "klassId":1, "name":"HelloWorld", "teacherId":2 } ## 返回数据 { "code":200, } ![https://box.kancloud.cn/7292c129b3c1aa1fdee95ac3edf08fb2_1138x1172.png](https://box.kancloud.cn/7292c129b3c1aa1fdee95ac3edf08fb2_1138x1172.png) ![https://box.kancloud.cn/6a2ae3c088bc600a39d8cd00e9017a4a_1000x692.png](https://box.kancloud.cn/6a2ae3c088bc600a39d8cd00e9017a4a_1000x692.png) ![https://box.kancloud.cn/6bb205bcf199222c607899e2d8855181_626x94.png](https://box.kancloud.cn/6bb205bcf199222c607899e2d8855181_626x94.png)