YoyoMooc.StuManagement.Api/Controllers/StudentController.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using YoyoMooc.StuManagement.Api.Repos;
using YoyoMooc.StuManagement.Models;
using YoyoMooc.StuManagement.Models.enums;
namespace YoyoMooc.StuManagement.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class StudentController:ControllerBase
{
private readonly IStudentRepository studentRepository;
public StudentController(IStudentRepository studentRepository)
{
this.studentRepository = studentRepository;
}
[HttpGet]
public async Task<ActionResult> GetStudentes()
{
try
{
return Ok(await studentRepository.GetStudents());
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError,
"从数据库检索数据出错");
}
}
[HttpGet("{id:int}")]
public async Task<ActionResult<Student>> GetStudent(int id)
{
try
{
var result = await studentRepository.GetStudent(id);
if (result == null) return NotFound();
return result;
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError,
"从数据库检索数据出错");
}
}
后面还有 102 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
