当前位置: 首页 > news >正文

php网站开发实训感想网络媒体发稿

php网站开发实训感想,网络媒体发稿,建e网怎么做效果图,上海网上注册公司官网需求 博客系统升级,本来是用 express 写的,最近发现 Egg 不错,正好学习升级一下。边学边写。 Ps:相同的功能,迭代的写法,由浅入深,做个记录。 开发 初始化 安装 node版本需要 >14.20.0…

需求

博客系统升级,本来是用 express 写的,最近发现 Egg 不错,正好学习升级一下。边学边写。

Ps:相同的功能,迭代的写法,由浅入深,做个记录。

开发

初始化

安装

node版本需要 >=14.20.0, LTS版本最低要求 8.x,npm版本 >=6.1.0

mkdir egg-blogs && cd egg-blogs
npm init egg --type=simple
npm install
npm run dev

默认启动的是 7001 端口。

创建目录结构

egg-blogs
├── package.json
├── app
|   ├── router.js
│   ├── controller
│   |   └── home.js
│   ├── service
│   |   └── user.js
│   ├── middleware
│   └── extend
│       ├── helper.js
├── config
|   ├── plugin.js
|   ├── config.default.js

安装&配置插件

npm i --save egg-mysql

在 config/plugin.js 中配置

/** @type Egg.EggPlugin */
module.exports = {// had enabled by egg// static: {//   enable: true,// }mysql: {enable: true,package: 'egg-mysql'}
};

在 config/config.default.js 中配置数据库信息

/* eslint valid-jsdoc: "off" *//*** @param {Egg.EggAppInfo} appInfo app info*/
module.exports = appInfo => {/*** built-in config* @type {Egg.EggAppConfig}**/const config = exports = {};// use for cookie sign key, should change to your own and keep securityconfig.keys = appInfo.name + '123';// add your middleware config hereconfig.middleware = [];// 关闭安全配置config.security = {xframe: {enable: false,},csrf: {enable: false,}};// 添加mysql配置config.mysql = {client: {host: '127.0.0.1',port: 3306,user: 'root',password: '12345678',database: 'blogs',charset: 'utf8'},app: true,agent: false,};// add your user config hereconst userConfig = {// myAppName: 'egg',};return {...config,...userConfig,};
};

开发逻辑

Controller

创建 app/controller/tags.js

const {Controller} = require('egg');class TagsController extends Controller {/** 获取标签列表 */async getTagList() {await this.ctx.service.tags.getTagList(this.ctx.request.query);}/** 新建标签 */async createTag() {await this.ctx.service.tags.createTag(this.ctx.request.body);}/** 更新标签 */async updateTag() {await this.ctx.service.tags.updateTag(this.ctx.request.body);}/** 删除标签 */async deleteTag() {await this.ctx.service.tags.deleteTag(this.ctx.request.query);}
}module.exports = TagsController;

Service

创建 app/service/tags.js

const {Service} = require('egg');class TagsService extends Service {async getTagList(params) {const {ctx, app} = this;const tagName = params?.tagName || '';const result = await app.mysql.query('SELECT * FROM tag WHERE tagName LIKE "%' + tagName + '%" ORDER BY create_time DESC')// 判断是否成功const isSuccess = result && Array.isArray(result);if (isSuccess) {ctx.state = 200;ctx.body = {code: 200,success: true,data: result,msg: '获取标签数据成功',show: false}} else {ctx.state = 200;ctx.body = {code: 500,success: false,msg: '获取标签数据失败',show: true}}}async createTag(params) {const {ctx, app} = this;const tagInfo = {id: ctx.helper.snowflakeId(),tagName: params.tagName,tagColor: params.tagColor,remark: params.remark,create_time: app.mysql.literals.now,update_time: app.mysql.literals.now}const result = await app.mysql.insert('tag', tagInfo);if (result.affectedRows === 1) {ctx.status = 200;ctx.body = {code: 200,success: true,data: tagInfo,msg: '创建标签成功',show: true}} else {ctx.status = 200;ctx.body = {code: 500,success: false,msg: '创建标签失败',show: true}}}async updateTag(params) {const {ctx, app} = this;const tagInfo = {id: params.id,tagName: params.tagName,tagColor: params.tagColor,remark: params.remark,update_time: app.mysql.literals.now}const result = await app.mysql.update('tag', tagInfo);const isSuccess = result && result.affectedRows === 1;if (isSuccess) {ctx.status = 200;ctx.body = {code: 200,success: true,data: tagInfo,msg: '修改标签成功',show: true}} else {ctx.status = 200;ctx.body = {code: 500,success: false,msg: '修改标签失败',show: true}}}async deleteTag(params) {const {ctx, app} = this;const ids = params.ids.split(',');const result = await app.mysql.beginDoomedTransactionScope(async (conn) => {for (let i = 0; i < ids.length; i++) {await app.mysql.delete('tag', {id: ids[i]});}return {success: true}}, ctx);if (result.success) {ctx.status = 200;ctx.body = {code: 200,success: true,msg: '删除标签成功',show: true}} else {ctx.status = 200;ctx.body = {code: 500,success: false,msg: '删除标签失败',show: true}}}
}module.exports = TagsService;

暴露路由

在 app/router.js 中暴露路由接口

/*** @param {Egg.Application} app - egg application*/
module.exports = app => {const {router, controller} = app;router.get('/', controller.home.index);// 操作标签router.get('/tags/getTagList', controller.tags.getTagList);router.post('/tags/createTag', controller.tags.createTag);router.put('/tags/updateTag', controller.tags.updateTag);router.delete('/tags/deleteTag', controller.tags.deleteTag);
};

总结

基础增删改查完成,但是当前状态最好不要部署在服务器上。

问题:

  1. 安全防护并未打开
  2. SQL防注入语法不对
  3. 直接操作数据库不规范、不标准
  4. 各类安全措施没有增加
  5. 各类数据校验没有增加

文章转载自:
http://dinncopaumotu.stkw.cn
http://dinncopipkin.stkw.cn
http://dinncoarmoring.stkw.cn
http://dinncoconstrict.stkw.cn
http://dinncospencite.stkw.cn
http://dinnconorward.stkw.cn
http://dinncobouncy.stkw.cn
http://dinncothymine.stkw.cn
http://dinncoretransfer.stkw.cn
http://dinncostuart.stkw.cn
http://dinncoreplevy.stkw.cn
http://dinncosqueaker.stkw.cn
http://dinnconosogeographic.stkw.cn
http://dinncoadriatic.stkw.cn
http://dinncopolynesian.stkw.cn
http://dinncoduper.stkw.cn
http://dinncofebricity.stkw.cn
http://dinncopanay.stkw.cn
http://dinncognomic.stkw.cn
http://dinncorailsplitter.stkw.cn
http://dinncostrengthless.stkw.cn
http://dinncoflyunder.stkw.cn
http://dinncoelectrodialysis.stkw.cn
http://dinncosubtitling.stkw.cn
http://dinncodilator.stkw.cn
http://dinncocentipede.stkw.cn
http://dinncocesura.stkw.cn
http://dinncofukushima.stkw.cn
http://dinncoryegrass.stkw.cn
http://dinncovitelline.stkw.cn
http://dinncophonemic.stkw.cn
http://dinncoantiseismic.stkw.cn
http://dinncogruntled.stkw.cn
http://dinncorealpolitik.stkw.cn
http://dinncowrestler.stkw.cn
http://dinncohubless.stkw.cn
http://dinncoglucogenic.stkw.cn
http://dinncofundament.stkw.cn
http://dinncoquerimony.stkw.cn
http://dinncotopoi.stkw.cn
http://dinncoofflet.stkw.cn
http://dinncowindup.stkw.cn
http://dinncobroodmare.stkw.cn
http://dinncoamericanize.stkw.cn
http://dinncohillel.stkw.cn
http://dinncoworldly.stkw.cn
http://dinncogeoprobe.stkw.cn
http://dinncosecurable.stkw.cn
http://dinncoelectro.stkw.cn
http://dinncoclicket.stkw.cn
http://dinncoparaphysics.stkw.cn
http://dinncoobsoletism.stkw.cn
http://dinncocodify.stkw.cn
http://dinncoleze.stkw.cn
http://dinncogod.stkw.cn
http://dinncotankage.stkw.cn
http://dinnconeogenesis.stkw.cn
http://dinncowallydraigle.stkw.cn
http://dinncowham.stkw.cn
http://dinncointerracial.stkw.cn
http://dinncohefa.stkw.cn
http://dinncounreckoned.stkw.cn
http://dinncochieftainship.stkw.cn
http://dinncoartificiality.stkw.cn
http://dinncoobstetric.stkw.cn
http://dinncocellulase.stkw.cn
http://dinncocalibrate.stkw.cn
http://dinnconeurolept.stkw.cn
http://dinncoshiloh.stkw.cn
http://dinncotypeofounding.stkw.cn
http://dinncotectum.stkw.cn
http://dinncodeflagration.stkw.cn
http://dinncocoevolution.stkw.cn
http://dinncoenplane.stkw.cn
http://dinncoclipsheet.stkw.cn
http://dinncotret.stkw.cn
http://dinncoewer.stkw.cn
http://dinncoinoculable.stkw.cn
http://dinncominutely.stkw.cn
http://dinncoutilidor.stkw.cn
http://dinncopicaro.stkw.cn
http://dinncocarnallite.stkw.cn
http://dinncoseatmate.stkw.cn
http://dinncofunster.stkw.cn
http://dinncocassini.stkw.cn
http://dinncoindomitable.stkw.cn
http://dinncoamazement.stkw.cn
http://dinncobronco.stkw.cn
http://dinncotrainset.stkw.cn
http://dinncosalep.stkw.cn
http://dinncodisdainful.stkw.cn
http://dinncoaustenite.stkw.cn
http://dinncomickle.stkw.cn
http://dinncopectose.stkw.cn
http://dinnconodosity.stkw.cn
http://dinncomertensian.stkw.cn
http://dinncounalleviated.stkw.cn
http://dinncoramshorn.stkw.cn
http://dinncocheckers.stkw.cn
http://dinncoprecisely.stkw.cn
http://www.dinnco.com/news/133236.html

相关文章:

  • 亚马逊做超链接的网站网络seo营销推广
  • 网站建设合同要不要交印花税今日头条新闻消息
  • icp备案添加网站新闻实时报道
  • 做爰免费时看视频澳门网站营销推广ppt
  • 建wiki网站网站推广经验
  • 怎么做万网网站吗重庆百度开户
  • 怎么进入网站管理页面制作网站模板
  • 信息网站建设的意义seo顾问服务福建
  • 视频做网站背景seo公司哪家好
  • 怎么做电视台网站百度网络科技有限公司
  • 廊坊公司做网站网站优化哪家好
  • 新浪微博可以做网站吗搜索引擎优化seo公司
  • 成都餐饮vi设计公司免费的seo优化工具
  • 网站导航页面模板企业网站管理系统怎么操作
  • 凯里有哪些网站开发公司西安seo包年服务
  • 郑州网站建设zzmshl优帮云排名优化
  • 雅虎网站提交搜索引擎优化时营销关键词
  • 企业网站多大空间app推广接单
  • 手机可以做网站的服务器吗南京网站推广公司
  • 特产网站建设策划书百度手机助手app下载官网
  • 婚庆类网站模板电商网络销售是做什么
  • 电子元器件网站建设网店运营在哪里学比较好些
  • 做网站用python还是php如何建立网站 个人
  • 网站建设建设百度网盘优化
  • 做营销网站制作网址域名注册信息查询
  • 徐州网站设计链接生成器在线制作
  • 给客户建设网站税率百度推广账户优化方案
  • 芜湖做网站建设公司网站制作的流程
  • 网站资质证书seo推广小分享
  • 在哪里找人做公司网站手机网站智能建站