//定义接口
interface DBI<T>{
add(info:T):boolean
get(id:number):any[]
}
//定义一个数据库类
class MysqlDb<T> implements DBI<T>{
add(info:T):boolean{
console.log(info);
return true
}
get(id:number):any{
var list = [
{
id:1,
name:'123'
}
]
return list
}
}
//定义第二个数据库类
class Mysql<T> implements DBI<T>{
add(info: T): boolean {
throw new Error("Method not implemented.");
}
get(id: number): any[] {
throw new Error("Method not implemented.");
}
}
//定义操作数据
class User {
username:string | undefined
password:string | undefined
}
//实例化user
var u = new User()
u.username = '11'
u.password = '222'
//实例化MysqlDb
var Db = new MysqlDb<User>()
Db.add(u)
console.log(Db.get(2));