# DelphiWebMVC
**Repository Path**: lim417/DelphiWebMVC
## Basic Information
- **Project Name**: DelphiWebMVC
- **Description**: 使用delphi技术开发的Web框架,使用MVC模式,只需把精力放在模型与视图的设计上,让delphi开发web系统更方便,代码在delphi10.2下编译通过,webbroker 使用了http.sys,性能上有了很大提升。
- **Primary Language**: Pascal
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: https://my.oschina.net/delphimvc
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 77
- **Created**: 2018-12-02
- **Last Updated**: 2021-01-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# DelphiWebMVC使用说明:
项目用到mORMot代码库,可到这里下载。
链接:https://pan.baidu.com/s/19j1QesY7kwluiK6tSd7jXQ 提取码:p24h
测试项目:http://47.98.102.37:8001/
讨论QQ群: 685072623
Action : 控制器类存放目录
Common : 框架相关代码
Config : 项目配置相关代码
Module : 数据库引擎及webbroker服务代码
Syn : https.sys相关类库
bin : 视图页面js,css,html,数据库配置相关资源
数据库连接与服务端口修改:
配置bin/config.ini 文件
例:
[MYSQL]
Server=127.0.0.1
Port=3307
DriverID=MySQL
Database=test
User_Name=root
Password=root
CharacterSet=utf8
Compress=False
Pooled=True
POOL_CleanupTimeout=30000
POOL_ExpireTimeout=90000
POOL_MaximumItems=50
[Server]
Root=
Port=8001
路由配置:
在Config/uRouleMap.pas 配置相关路由
例:
unit uRouleMap;
interface
uses
Roule;
type
TRouleMap = class(TRoule)
public
constructor Create(); override;
end;
implementation
uses
LoginAction, UsersAction, MainAction, IndexAction, KuCunAction;
constructor TRouleMap.Create;
begin
inherited; //必须继承
//参数说明: 路径;控制器;视图目录
SetRoule('/', TLoginAction, 'login');
SetRoule('/Main', TMainAction, 'main');
SetRoule('/Users', TUsersAction, 'users');
SetRoule('/kucun', TKuCunAction, 'kucun');
end;
end.
控制器开发:
存放在Action文件夹
例:
unit LoginAction;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, Data.DB, superobject,
BaseAction;
type
TLoginAction = class(TBaseAction)
public
procedure index();
procedure check();
procedure checknum();
end;
implementation
uses
uTableMap;
procedure TLoginAction.check();
var
json: string;
sdata, ret: ISuperObject;
username, pwd: string;
sql: string;
begin
ret := SO();
with View do
begin
try
username := Input('username');
pwd := Input('pwd');
Sessionset('username', username);
json:=Sessionget('username');
sql := ' and username=' + Q(username) + ' and pwd=' + Q(pwd);
sdata := Db.FindFirst(tb_users, sql);
if (sdata <> nil) then
begin
json:=sdata.AsString;
Sessionset('username', username);
Sessionset('name', sdata.S['name']);
ret.I['code'] := 0;
ret.S['message'] := '登录成功';
end else begin
ret.I['code'] := -1;
ret.S['message'] := '登录失败';
end;
ShowJson(ret);
except on e:Exception do
ShowText(e.ToString);
end;
end;
end;
procedure TLoginAction.checknum;
var
num:string;
begin
Randomize;
num:= inttostr(Random(9))+inttostr(Random(9))+inttostr(Random(9))+inttostr(Random(9));
View.ShowCheckIMG(num,60,30);
end;
procedure TLoginAction.index();
begin
with View do
begin
ShowHTML('Login');
end;
end;
end.
拦截器配置:
在 Config/BaseAction.pas 修改 TBaseAction.Interceptor 函数
例:
function TBaseAction.Interceptor: boolean; //拦截器
var
url: string;
begin
Result := false;
with View do
begin
url := LowerCase(Request.PathInfo);
if (Error) then
begin
Result := true;
exit;
end;
if (url <> '/') and (url <> '/index')
and (url <> '/check')
and (url <> '/checknum')
and (url <> '/favicon.ico') then
begin
if (SessionGet('username') = '') then
begin
Result := true;
Response.Content := '';
Response.SendResponse;
end;
end;
end;
end;
框架当前实现了三个标记:
<#include file='/public.html' />
<#for list="sdata" htmlfile="table.html" />
<#if when='sex=1' then='男' else='女' />

table.html文件:

页面数据变量值传入
