分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

go案例:客户管理系统流程 ?mvc模式 分层设计

发布时间:2023-09-06 02:26责任编辑:彭小芳关键词:暂无标签

下面是一个简要的客服系统,主要是演示分层计。。

model : 数据部份:

package modelimport "fmt"//声明一个结构体,表示一个客户信息type Customer struct{ ???Id int ???Name string ???Gender string ???Age int ???Phone string ???Emaill string}func NewCustomer(id int,name string, gender string, ???age int, phone string,email string) Customer{ ???????return Customer{ ???????????Id : id, ???????????Name : name, ???????????Gender : gender, ???????????Age : age, ???????????Phone:phone, ???????}}func NewCustomer2(name string, gender string, ???age int, phone string,email string) Customer{ ???return Customer{ ???????Name : name, ???????Gender : gender, ???????Age : age, ???????Phone:phone, ???}}func (this Customer) GetInfo() string{ info := fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v\t",this.Id, ????this.Name,this.Gender,this.Age,this.Phone,this.Emaill) return info}
View Code

控制层,这儿名为服务层 customerService 代码如下:

package modelimport "fmt"//声明一个结构体,表示一个客户信息type Customer struct{ ???Id int ???Name string ???Gender string ???Age int ???Phone string ???Emaill string}func NewCustomer(id int,name string, gender string, ???age int, phone string,email string) Customer{ ???????return Customer{ ???????????Id : id, ???????????Name : name, ???????????Gender : gender, ???????????Age : age, ???????????Phone:phone, ???????}}func NewCustomer2(name string, gender string, ???age int, phone string,email string) Customer{ ???return Customer{ ???????Name : name, ???????Gender : gender, ???????Age : age, ???????Phone:phone, ???}}func (this Customer) GetInfo() string{ info := fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v\t",this.Id, ????this.Name,this.Gender,this.Age,this.Phone,this.Emaill) return info}
View Code

最后是视图层:第一个版本没有加注释,以后有空成全功能后在认真写好注释

package mainimport ( ???"fmt" ???"awesomeProject/service" ???"awesomeProject/model")type customerView struct{ ???key string ???loop bool ???customerService *service.CustomerService}//显示用户例表func(this *customerView) list(){ ???customers:=this.customerService.List() ???fmt.Println("——————————————————客户例表————————————————————————————") ???fmt.Println("编号 \t 姓名 \t \t性别 \t年龄 \t电话 \t邮箱") ???for i:=0; i < len(customers);i++{ ???????fmt.Println(customers[i].GetInfo()) ???} ???fmt.Println("++++++++++++++客户列表完成+++++++++++++++")}//jo fi addfunc(this *customerView)add(){ ???fmt.Println("-----------------添加客户----------------") ???fmt.Println("姓名") ???name := "" ???fmt.Scanln(&name) ???fmt.Println("姓别") ???gender:="" ???fmt.Scanln(&gender) ???fmt.Println("请输入年龄") ???age :=0 ???fmt.Scanln(&age) ???fmt.Println("请输入电话") ???phone :="" ???fmt.Scanln(&phone) ???fmt.Println("请输入邮箱") ???email:="" ???fmt.Scanln(&email) ???customer :=model.NewCustomer2(name,gender,age, phone,email) ???this.customerService.Add(customer)}func(this *customerView)delete(){ ???fmt.Println("______________删除客户————————————————————————") ???fmt.Println("请输入客户编号(-1退出)") ???id := -1 ???fmt.Scanln(&id) ???if id == -1{ ???????return ???} ???fmt.Println("请确认删除y/n") ???choice :="" ???fmt.Scanln(&choice) ???if choice == "y"||choice =="Y"{ ???????if this.customerService.Delete(id){ ???????????fmt.Println("____________删 除成功__________________") ???????}else{ ???????????fmt.Println("删 除失败,可能是输入的Id不存在") ???????} ???}}func(this *customerView)mainMenu(){ ???for{ ???????fmt.Println("————————————————客户信息管理软件————————————————————————") ???????fmt.Println(" ??????????????1 添加客户 ??????????????????????????????") ???????fmt.Println(" ??????????????2 修改客户 ???????????????????????????????") ???????fmt.Println(" ??????????????3 删除客服 ???????????????????????????????") ???????fmt.Println(" ??????????????4 客户例表 ???????????????????????????????") ???????fmt.Println( ?" ????????????5 退出 ???????????????????????????????????") ???????fmt.Println( ????????????????"请选择(1-5)") ???????fmt.Scanln(&this.key) ???????switch this.key { ???????case "1": ???????????this.add() ???????case "2": ???????????fmt.Println("修改用户") ???????case "3": ???????????this.delete() ???????case "4": ???????????this.list() ???????case "5": ???????????this.loop = false ???????default: ???????????fmt.Println("输入有误 ") ???????}//switch循环结束 ???????if !this.loop{ ???????????break ???????}//for ?????} ???fmt.Println("你退出了客户系统")}//主函数func main(){ ????customerView := customerView{ ???????key: "", ???????loop : true, ???} ????customerView.customerService = service.NewcustomerService() ???customerView.mainMenu()}
View Code

go案例:客户管理系统流程 ?mvc模式 分层设计

原文地址:https://www.cnblogs.com/fgxwan/p/10111556.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved