mormot2路由

mormot2路由

1)

uses 

mormot.net.server,
mormot.core.data,

var fRouter: TUriRouter;

function _Router: TUriRouter;
begin
if not Assigned(fRouter) then
begin
fRouter := TUriRouter.Create(TUriTreeNode, [rtoCaseInsensitiveUri]);
end;
Result := fRouter;
end;

2)fserver.ReplaceRoute(_router);    //set router       

3) 

unit api.danwei2;
//cxg 2024-7-18
//单表CRUD
{$ifdef fpc}
{$mode delphi}{$H+}
{$endif}

interface

uses  DB.table.crud, uni, DB.unidac, DB.unidacpool, sys.global,
  fpjson, jsonparser,
  SysUtils, Classes;

type
  Tdanwei = record
    function select(ctxt: Tcontext): cardinal;  //查询
    function insert(ctxt: Tcontext): cardinal;  //新增
    function update(ctxt: Tcontext): cardinal;  //修改
    function Delete(ctxt: Tcontext): cardinal;  //删除
  end;

implementation

function Tdanwei.select(ctxt: Tcontext): cardinal;
var
  crud: Tcrud;
begin
  crud.dbid := '1';
  crud.ctxt := ctxt;
  crud.sql := 'select * from tunit';
  crud.format := foJson;
  crud.select;
end;

function Tdanwei.insert(ctxt: Tcontext): cardinal;
var
  crud: Tcrud;
begin
  crud.dbid := '1';
  crud.ctxt := ctxt;
  crud.tableName := 'tunit';
  crud.nonFields := '';
  crud.state := stInsert;
  crud.format := foJson;
  crud.exec;
end;

function Tdanwei.update(ctxt: Tcontext): cardinal;
var
  crud: Tcrud;
begin
  crud.dbid := '1';
  crud.ctxt := ctxt;
  crud.tableName := 'tunit';
  crud.nonFields := '';
  crud.state := stUpdate;
  crud.format := foJson;
  crud.exec;
end;

function Tdanwei.Delete(ctxt: Tcontext): cardinal;
var
  crud: Tcrud;
begin
  crud.dbid := '1';
  crud.ctxt := ctxt;
  crud.tableName := 'tunit';
  crud.state := stDelete;
  crud.format := foJson;
  crud.exec;
end;

var _: Tdanwei;

initialization
  _router.Post('/danwei/qry', _.select);
  _router.Post('/danwei/add', _.insert);
  _router.Post('/danwei/edit', _.updat);
  _router.Post('/danwei/del', _.delete);

end.

 

posted @ 2024-07-17 17:42  delphi中间件  阅读(43)  评论(0编辑  收藏  举报