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.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/18307972