This commit is contained in:
Redkale
2016-11-25 15:53:37 +08:00
parent 92aff864ef
commit 9bc60c1c47
4 changed files with 27 additions and 21 deletions

View File

@@ -25,6 +25,7 @@ public class HelloEntity {
@RestAddress
private String clientaddr;
/** 以下省略getter setter方法 */
public int getHelloid() {
return helloid;
}

View File

@@ -14,7 +14,7 @@ import org.redkale.util.Sheet;
* Flipper : Source组件中的翻页对象
* UserInfo :当前用户类
* HelloEntity: Hello模块的实体类
* HelloBean: Hellow模块实现FilterBean的过滤Bean类
* HelloBean: Hello模块实现FilterBean的过滤Bean类
*
*/
@RestService

View File

@@ -16,7 +16,7 @@ import org.redkale.util.Sheet;
* Flipper : Source组件中的翻页对象
* UserInfo :当前用户类
* HelloEntity: Hello模块的实体类
* HelloBean: Hellow模块实现FilterBean的过滤Bean类
* HelloBean: Hello模块实现FilterBean的过滤Bean类
*
*/
@RestService(name = "hello", moduleid = 0, repair = true, ignore = false, comment = "Hello服务模块")
@@ -27,7 +27,7 @@ public class HelloService2 implements Service {
//增加记录
@RestMapping(name = "create", auth = false, comment = "创建Hello对象")
public RetResult<HelloEntity> createHello(UserInfo info, @RestParam(name = "bean") HelloEntity entity) {
public RetResult<HelloEntity> createHello(UserInfo info, @RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) {
entity.setCreator(info == null ? 0 : info.getUserid()); //设置当前用户ID
entity.setCreatetime(System.currentTimeMillis());
source.insert(entity);
@@ -36,26 +36,26 @@ public class HelloService2 implements Service {
//删除记录
@RestMapping(name = "delete", auth = false, comment = "根据id删除Hello对象")
public void deleteHello(@RestParam(name = "#") int id) { //通过 /hello/delete/1234 删除对象
public void deleteHello(@RestParam(name = "#", comment = "Hello对象id") int id) { //通过 /hello/delete/1234 删除对象
source.delete(HelloEntity.class, id);
}
//修改记录
@RestMapping(name = "update", auth = false, comment = "修改Hello对象")
public void updateHello(@RestParam(name = "bean") HelloEntity entity) { //通过 /hello/update?bean={...} 修改对象
public void updateHello(@RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) { //通过 /hello/update?bean={...} 修改对象
entity.setUpdatetime(System.currentTimeMillis());
source.update(entity);
}
//查询列表
@RestMapping(name = "query", auth = false, comment = "修改Hello对象部分属性")
public Sheet<HelloEntity> queryHello(@RestParam(name = "bean") HelloBean bean, Flipper flipper) { //通过 /hello/query/offset:0/limit:20?bean={...} 查询列表
@RestMapping(name = "query", auth = false, comment = "查询Hello对象列表")
public Sheet<HelloEntity> queryHello(@RestParam(name = "bean", comment = "过滤条件") HelloBean bean, Flipper flipper) { //通过 /hello/query/offset:0/limit:20?bean={...} 查询列表
return source.querySheet(HelloEntity.class, flipper, bean);
}
//查询单个
@RestMapping(name = "find", auth = false, comment = "根据id查找单个Hello对象")
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /hello/find/1234 查询对象
public HelloEntity findHello(@RestParam(name = "#", comment = "Hello对象id") int id) { //通过 /hello/find/1234 查询对象
return source.find(HelloEntity.class, id);
}
}

View File

@@ -27,19 +27,21 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
private Map<String, HelloService2> _servicemap;
@AuthIgnore
@WebAction(url = "/hello/create")
@WebAction(url = "/hello/create", comment = "创建Hello对象")
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
public void create(HttpRequest req, HttpResponse resp) throws IOException {
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
bean.setClientaddr(req.getRemoteAddr());
bean.setResname(req.getHeader("hello-res"));
bean.setClientaddr(req.getRemoteAddr());
bean.setResname(req.getHeader("hello-res"));
UserInfo user = currentUser(req);
RetResult<HelloEntity> result = service.createHello(user, bean);
resp.finishJson(result);
}
@AuthIgnore
@WebAction(url = "/hello/delete/")
@WebAction(url = "/hello/delete/", comment = "根据id删除Hello对象")
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
int id = Integer.parseInt(req.getRequstURILastPath());
@@ -48,32 +50,35 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
}
@AuthIgnore
@WebAction(url = "/hello/update")
@WebAction(url = "/hello/update", comment = "修改Hello对象")
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
public void update(HttpRequest req, HttpResponse resp) throws IOException {
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
bean.setClientaddr(req.getRemoteAddr());
bean.setResname(req.getHeader("hello-res"));
bean.setClientaddr(req.getRemoteAddr());
bean.setResname(req.getHeader("hello-res"));
service.updateHello(bean);
resp.finishJson(RetResult.success());
}
@AuthIgnore
@WebAction(url = "/hello/query")
@WebAction(url = "/hello/query", comment = "查询Hello对象列表")
@WebParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
public void query(HttpRequest req, HttpResponse resp) throws IOException {
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
bean.setClientaddr(req.getRemoteAddr());
bean.setUseragent(req.getHeader("User-Agent"));
bean.setRescookie(req.getCookie("hello-cookie"));
bean.setSessionid(req.getSessionid(false));
bean.setClientaddr(req.getRemoteAddr());
bean.setUseragent(req.getHeader("User-Agent"));
bean.setRescookie(req.getCookie("hello-cookie"));
bean.setSessionid(req.getSessionid(false));
Flipper flipper = req.getFlipper();
Sheet<HelloEntity> result = service.queryHello(bean, flipper);
resp.finishJson(result);
}
@AuthIgnore
@WebAction(url = "/hello/find/")
@WebAction(url = "/hello/find/", comment = "根据id删除Hello对象")
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
public void find(HttpRequest req, HttpResponse resp) throws IOException {
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
int id = Integer.parseInt(req.getRequstURILastPath());