import 'package:aqueduct/aqueduct.dart';
import 'package:demo2/model/model.dart';
class UserController extends ResourceController {
UserController(this.context);
ManagedContext context;
@Operation.get()
Future<Response> getAllUser() async {
final query = Query<Model>(context);
final allUser = await query.fetch();
return Response.ok(allUser);
}
@Operation.post()
Future<Response> insertUser(@Bind.body() Model model) async {
final query = Query<Model>(context);
query.values = model;
final user = await query.insert();
return Response.ok(user);
}
}
视频教程查看以下链接
https://www.bilibili.com/video/BV1C54y1Y7Lm