|
|
|
@ -24,23 +24,36 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 首页轮播图相关的接口控制器类,主要负责向外提供获取首页轮播图列表信息的接口,
|
|
|
|
|
* 通过调用对应的服务层方法获取数据,并进行必要的数据转换后返回给客户端。
|
|
|
|
|
*
|
|
|
|
|
* @author lanhai
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
// 使用 @Tag 注解为该控制器类添加标签说明,用于在 API 文档(如 Swagger 生成的文档)中对该类下的接口进行分类展示,这里表明是“首页轮播图接口”相关的一组接口。
|
|
|
|
|
@Tag(name = "首页轮播图接口")
|
|
|
|
|
public class IndexImgController {
|
|
|
|
|
|
|
|
|
|
// 注入IndexImgService,用于与首页轮播图相关的业务逻辑处理,例如从数据库中查询轮播图列表等操作。
|
|
|
|
|
@Autowired
|
|
|
|
|
private IndexImgService indexImgService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 首页轮播图接口
|
|
|
|
|
* 首页轮播图接口方法,用于获取首页轮播图的列表信息,并将其返回给客户端。
|
|
|
|
|
* 通过 @GetMapping 注解将该方法映射到 HTTP 的 GET 请求方式,请求路径为“/indexImgs”,客户端可以通过该路径访问此接口获取数据。
|
|
|
|
|
* @Operation 注解用于在 API 文档中对该接口进行详细描述,包括接口的简要说明(summary)和详细描述(description),方便接口使用者了解接口的功能。
|
|
|
|
|
*
|
|
|
|
|
* @return 返回一个包含首页轮播图信息的ServerResponseEntity对象,若获取成功则响应体中包含轮播图列表数据(以IndexImgDto列表形式返回),否则返回相应错误信息。
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/indexImgs")
|
|
|
|
|
@Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
|
|
|
|
|
@Operation(summary = "首页轮播图", description = "获取首页轮播图列表信息")
|
|
|
|
|
public ServerResponseEntity<List<IndexImgDto>> indexImgs() {
|
|
|
|
|
// 调用IndexImgService的listIndexImg方法,从数据库或其他数据源获取首页轮播图的原始数据列表(以IndexImg对象列表形式返回)。
|
|
|
|
|
List<IndexImg> indexImgList = indexImgService.listIndexImg();
|
|
|
|
|
// 使用hutool的BeanUtil工具类,将IndexImg对象列表转换为IndexImgDto对象列表,IndexImgDto可能是用于对外展示的、经过筛选或格式调整后的视图对象,
|
|
|
|
|
// 这样可以避免直接将内部的业务实体对象暴露给客户端,更好地控制数据的展示格式和安全性。
|
|
|
|
|
List<IndexImgDto> indexImgDtos = BeanUtil.copyToList(indexImgList, IndexImgDto.class);
|
|
|
|
|
// 将转换后的IndexImgDto列表封装在表示成功的ServerResponseEntity对象中返回给客户端,遵循统一的接口响应格式规范。
|
|
|
|
|
return ServerResponseEntity.success(indexImgDtos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|