package Schooltype SchoolModel struct { Name string Address string StudentCount int Is985 bool}type ISchoolDal interface { GetList() Add() Delete()}
package Schooltype SchoolDal struct {}func (o *SchoolDal) GetList() []SchoolModel { var result []SchoolModel if (result == nil) { println("切片是空的") } var t = SchoolModel{ "江西财大", "南昌市", 1000, false} var t2 = SchoolModel{ "江西财大2", "南昌市", 1000, false} result = append(result, t) result = append(result, t2) return result}func (o *SchoolDal) Add(m SchoolModel) { println("这里是Add")}func (o *SchoolDal) Delete(m SchoolModel) { println("这里是Delete")}
访问权限:
1.类、方法首字段小写:仅仅同一个包访问2.反之,大写:全项目访问
package mainimport "Study1/dto"func main() { //可以访问dto.Student ,首字母大写 var stu = dto.Student{ "111","ligenyun",11} println(stu.Sname) //不可以访问dto.student ,首字母写写 var stu2 = dto.student{ "111","ligenyun",11} println(stu2.sname)}
package dtotype Student struct { Sno string Sname string Sage int}type student2 struct { sno string sname string sage int}