### Download File Utility (Java) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/file This Java code demonstrates how to download files using the `OssSaveUtil` utility. The `download()` method abstracts the storage type (local or MinIO) based on the configuration, returning an `InputStream` for further processing. The example shows how to call it for both local and MinIO stored files. ```java // 本地存储 InputStream inputStream = OssSaveUtil.download("/vpath/data/image/png/aaaa.jpg"); // Minio存储 InputStream inputStream = OssSaveUtil.download("http://minio-s3.cnsaas.com/scaffold-boot-3/aaaa.jpg"); ``` -------------------------------- ### Copy and Secure libtirpc Library (Shell) Source: https://szzf.cnsaas.com/scaffold-boot-docs/localization/kylin-v10 Steps to copy a specific libtirpc shared library from one machine to another and set its permissions and SELinux context. This is a workaround for potential NFS startup issues. ```shell sudo scp /usr/lib64/libtirpc.so.3 root@172.21.136.5:/usr/lib64/ sudo chmod 755 /usr/lib64/libtirpc.so.3 sudo restorecon -v /usr/lib64/libtirpc.so.3 ``` -------------------------------- ### Generated User Management Controller Example (Java) Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt This Java snippet provides an example of a generated Controller for user management, including endpoints for pagination, detail retrieval, creation, update, and deletion. It utilizes common Spring Boot annotations and data transfer objects. ```java // 生成的Controller示例 @RestController @RequestMapping("/admin/user") @Api(tags = "用户管理") public class UserController { @Autowired private IUserService baseService; @ApiOperation("分页查询") @PostMapping("/pageQuery") public Result pageQuery(@RequestBody UserParams params) { IPage result = baseService.page(params).convert(it -> { UserPageQueryResultVO record = new UserPageQueryResultVO(); BeanUtils.copyProperties(it, record); return record; }); DataConvertUtil.trans(result.getRecords()); return new JsonResult<>(result); } @ApiOperation("详情查询") @GetMapping("/detail") public Result detail(@RequestParam Long id) { User entity = baseService.getById(id); UserDetailResultVO result = new UserDetailResultVO(); BeanUtils.copyProperties(entity, result); DictTransUtil.trans(result); return new JsonResult<>(result); } @ApiOperation("新增") @PostMapping("/save") public Result save(@RequestBody @Validated User entity) { baseService.save(entity); return Result.ok(); } @ApiOperation("修改") @PostMapping("/update") public Result update(@RequestBody @Validated User entity) { baseService.updateById(entity); return Result.ok(); } @ApiOperation("删除") @DeleteMapping("/remove") public Result remove(@RequestParam Long id) { baseService.removeById(id); return Result.ok(); } } ``` -------------------------------- ### Install RPM Packages (Shell) Source: https://szzf.cnsaas.com/scaffold-boot-docs/localization/kylin-v10 Command to forcefully install all RPM packages within the current directory. It uses `--nodeps --force` to bypass dependency checks and overwrite existing packages, which should be used with caution. ```shell cd into each directory rpm -Uvh *.rpm --nodeps --force ``` -------------------------------- ### File Upload and Download with MinIO/Local Storage (Java) Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt Provides Java code for uploading and downloading files, supporting both MinIO and local storage. It includes controller endpoints for upload and download, and configuration examples for application.yml. Upload requires a MultipartFile and optionally serverCode and name. Download requires a file path. Dependencies include Spring Boot, MinIO client (if used), and utility classes for stream handling. ```java // 上传文件 @RestController @RequestMapping("/admin/oss") public class SysOssController { @Autowired private ISysOssService baseService; @ApiOperation("上传文件") @PostMapping(value = "/upload") public Result upload(@RequestParam(name = "file") MultipartFile file, @RequestParam(name = "serverCode", required = false) String serverCode, @RequestParam(name = "name", required = false) String name) { if (StringUtil.isEmpty(serverCode)) { serverCode = ossProperties.getDefaultType(); } if (file == null || file.isEmpty()) { return new Result(ResultCode.BAD_REQUEST, "请选择要上传的文件"); } SysOss upload = baseService.upload(file, serverCode, name); return new JsonResult<>(upload); } } // 下载文件 @ApiOperation("下载文件") @GetMapping("/download") public void downloadFile(@RequestParam String filePath) { // 根据存储类型自动判断本地或MinIO InputStream inputStream = OssSaveUtil.download(filePath); // 处理输入流,输出到Response SystemUtil.outputStreamToResponse(inputStream, "文件名.pdf"); } // application.yml配置示例(MinIO) // oss: // config: // default-type: Minio // support-ext: xls,xlsx,doc,docx,pdf,jpg,jpeg,png,mp4 // minio: // endpoint: http://minio-s3.cnsaas.com // accessKey: your-access-key // secret: your-secret // bucket: your-bucket // application.yml配置示例(本地存储) // oss: // config: // default-type: LocalServer // support-ext: xls,xlsx,doc,docx,pdf,jpg,jpeg,png,mp4 // local-oss: // path: /mnt/data/file // url: /vpath/data ``` -------------------------------- ### 封装的用户登录方法 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security 对 SaToken 的 login 方法进行了二次封装,增加了刷新上下文信息的功能。在集成其他登录途径时,会调用此方法。 ```java /** * 登录用户,并刷新上下文信息 * @param client 登录的客户端 * @param username 用户名 * @return SaTokenInfo 登录信息 */ private SaTokenInfo loginUser(String client, String username) { StpUtil.login(username, client); refreshContextUserInfo(client, username); return StpUtil.getTokenInfo(); } ``` -------------------------------- ### Extract Tar Archives (Shell) Source: https://szzf.cnsaas.com/scaffold-boot-docs/localization/kylin-v10 Commands to extract tar.gz archives to a specified directory. Assumes the tarballs contain RPM packages for installation. ```shell tar -xzvf nfs.tar.gz -C /root tar -xzvf java.tar.gz -C /root tar -xzvf redis.tar.gz -C /root tar -xzvf nginx.tar.gz -C /root tar -xzvf vnc.tar.gz -C /root ``` -------------------------------- ### Java: Controller下载Excel模板 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/excel 提供下载Excel模板的功能,通过`SystemUtil.downloadClassPathFile()`方法读取classpath下的模板文件并输出到HTTP响应流。前端可调用此接口实现模板下载。 ```java @ApiOperation("下载模板") @GetMapping("/downloadTemplate") public void downloadTemplate() { SystemUtil.downloadClassPathFile("/data/excelTemplate/duty_meeting_import_template.xlsx"); } ``` -------------------------------- ### 栏位管理 API Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 提供配置项目导航栏栏位的接口,支持树形结构,可设置排序、图标和跳转链接。 ```APIDOC ## GET /api/column/getChildColumnList ### Description 获取指定父编码下的子栏位数据,用于构建第一级栏位列表。 ### Method GET ### Endpoint /api/column/getChildColumnList ### Parameters #### Query Parameters - **code** (String) - Required - 父栏位的编码 ### Response #### Success Response (200) - **data** (List) - 栏位信息列表 - **msg** (String) - 消息 - **code** (Integer) - 状态码 ``` ```APIDOC ## GET /api/column/cascadeByCode ### Description 根据父编码获取所有栏位数据,并以树形结构返回,适用于级联选择器等场景。 ### Method GET ### Endpoint /api/column/cascadeByCode ### Parameters #### Query Parameters - **code** (String) - Required - 父栏位的编码 ### Response #### Success Response (200) - **data** (List) - 栏位级联数据列表 - **msg** (String) - 消息 - **code** (Integer) - 状态码 ``` -------------------------------- ### 微信小程序配置与接口调用 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/wechat 展示了微信小程序的 AppID 和密钥配置,以及通过 `WxMaService` 调用获取用户手机号接口的 Java 代码示例。需要配置 `wx.miniapp` 属性,并注入 `WxMaService`。 ```properties wx: miniapp: appid: APPID secret: 密钥 ``` ```java @Autowired private WxMaService wxService; //例:获取微信小程序手机号 public String getWechatPhone(String jsCode) { try { WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService().getPhoneNoInfo(jsCode); return wxMaPhoneNumberInfo.getPurePhoneNumber(); } catch (WxErrorException e) { log.error("获取手机号失败", e); throw new BusinessException(ResultCode.BAD_REQUEST, "获取手机号失败"); } } ``` -------------------------------- ### GET /api/bulletin/getById Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms Retrieves the details of a specific website notification or announcement by its unique identifier. ```APIDOC ## GET /api/bulletin/getById ### Description Retrieves the full details of a single website notification or announcement using its unique ID. ### Method GET ### Endpoint /api/bulletin/getById ### Parameters #### Query Parameters - **id** (Long) - Required - The unique identifier of the bulletin to retrieve. ### Request Example ``` { "id": 3 } ``` ### Response #### Success Response (200) - **data** (Bulletin) - A Bulletin object containing the details of the specified notification or announcement. #### Response Example ```json { "code": 200, "msg": "Operation successful", "data": { "id": 3, "title": "System Update", "content": "Details about the upcoming system update.", "type": "PC", "createTime": "2023-10-26T09:00:00Z" } } ``` ``` -------------------------------- ### GET /api/bulletin/getHomePageList Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms Retrieves a list of website notifications or announcements suitable for display on the homepage. ```APIDOC ## GET /api/bulletin/getHomePageList ### Description Retrieves a list of website notifications and announcements specifically curated for display on the website's homepage. ### Method GET ### Endpoint /api/bulletin/getHomePageList ### Parameters None ### Request Example (No request body needed) ### Response #### Success Response (200) - **data** (List[Bulletin]) - A list of Bulletin objects intended for the homepage. #### Response Example ```json { "code": 200, "msg": "Operation successful", "data": [ { "id": 2, "title": "Homepage Feature", "content": "Special content for the homepage.", "type": "Homepage", "createTime": "2023-10-27T11:00:00Z" } ] } ``` ``` -------------------------------- ### 配置本地OSS文件存储 Source: https://szzf.cnsaas.com/scaffold-boot-docs/advanced/config-java 配置类用于实现将本地磁盘文件映射至静态资源目录,实现接口访问。文件路径及访问地址配置在相应环境的application.yml中。支持多种文件类型。 ```yaml oss: config: #只有配置LocalServer才生效 default-type: LocalServer support-ext: xls,xlsx,doc,docx,ppt,pptx,pdf,txt,jpg,jpeg,png,gif,bmp,zip,rar,7z,pdf,mp4,avi,mov local-oss: path: D:/file/ url: /vpath/data ``` -------------------------------- ### GET /api/bulletin/getListByType Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms Retrieves a list of website notifications or announcements filtered by a specific type. This is useful for displaying content in different sections like PC or mobile. ```APIDOC ## GET /api/bulletin/getListByType ### Description Retrieves a list of website notifications or announcements based on the provided type. This allows for content differentiation, such as content for PC or mobile. ### Method GET ### Endpoint /api/bulletin/getListByType ### Parameters #### Query Parameters - **type** (String) - Required - The type of bulletin to retrieve (e.g., 'PC', 'mobile'). ### Request Example ``` { "type": "PC" } ``` ### Response #### Success Response (200) - **data** (List[Bulletin]) - A list of Bulletin objects matching the specified type. #### Response Example ```json { "code": 200, "msg": "Operation successful", "data": [ { "id": 1, "title": "Sample Announcement", "content": "This is a sample announcement content.", "type": "PC", "createTime": "2023-10-27T10:00:00Z" } ] } ``` ``` -------------------------------- ### 短信验证码登录实现 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security 实现了短信验证码登录逻辑,包括查询用户信息、校验短信验证码、销毁 Redis 中的验证码,并最终调用封装的 loginUser 方法完成登录。 ```java @Override public SaTokenInfo smsLogin(String client, String mobile, String smsCode) { User user = userService.lambdaQuery().eq(User::getMobile, mobile).one(); final String username = user.getUsername(); basicUserLoginValid(username); // 校验验证码 final String redisKey = SecurityCons.SMS_CODE_REDIS_KEY + mobile; String redisSmsCode = redisService.get(redisKey); if (StringUtil.isEmpty(smsCode) || !smsCode.equals(redisSmsCode)) { throw new BusinessException(ResultCode.BAD_REQUEST, "验证码错误"); } // 验证后立即销毁key redisService.remove(redisKey); return loginUser(client, username); } ``` -------------------------------- ### 后台用户登录接口 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security 提供基于账号密码的登录接口,接收用户名、密码和验证码。在调用时,前端需要对用户名和密码进行 Base64 编码。此接口会校验用户信息并生成 Token。 ```java @ApiOperation("用户登录") @PostMapping(value = "/login") public Result login(@RequestBody @Validated PasswordLoginDto dto) { // 验证图片验证码... return new JsonResult<>(loginService.passwordLogin(SecurityCons.Client.MANAGE, Base64.decodeStr(dto.getUsername()), Base64.decodeStr(dto.getPassword()))); } ``` -------------------------------- ### Get Logged-in User Information API Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security Retrieves the details of the currently logged-in user associated with the active token. This endpoint is located in UserController for historical reasons. ```APIDOC ## GET /loginUser ### Description Fetches the details of the currently logged-in user based on the active token. ### Method GET ### Endpoint /loginUser ### Parameters None ### Request Example ``` GET /loginUser ``` ### Response #### Success Response (200) - **code** (integer) - Response status code. - **msg** (string) - Response message. - **data** (object) - Contains the user's details. - **id** (string) - User's unique identifier. - **username** (string) - User's username. - **nickname** (string) - User's nickname. - **avatar** (string) - URL to the user's avatar. - **roles** (array) - List of user's roles. - **permissions** (array) - List of user's permissions. #### Response Example ```json { "code": 200, "msg": "Success", "data": { "id": "1", "username": "admin", "nickname": "Administrator", "avatar": "/avatars/default.png", "roles": ["admin", "editor"], "permissions": ["read:users", "write:posts"] } } ``` ``` -------------------------------- ### JSON Response for Successful Import Source: https://szzf.cnsaas.com/scaffold-boot-docs/sample/excel-import Example JSON structure for a successful Excel data import. It indicates success and provides the count of imported items. ```json { "success": true, "successCount": 10 } ``` -------------------------------- ### Single Table Pagination Query with MyBatis-Plus Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt Implements single-table pagination queries using MyBatis-Plus. Query conditions are configured via annotations on the parameters class. This example shows the parameter class and controller implementation. ```java import com.baomidou.mybatisplus.core.metadata.IPage; import com.fykj.scaffold.common.annotation.MatchType; import com.fykj.scaffold.common.annotation.QueryType; import com.fykj.scaffold.common.domain.params.BaseParams; import com.fykj.scaffold.common.domain.vo.Result; import com.fykj.scaffold.common.domain.vo.Result.JsonResult; import com.fykj.scaffold.common.util.DataConvertUtil; import com.fykj.scaffold.cdo.domain.param.CdoContactParams; import com.fykj.scaffold.cdo.domain.vo.CdoContactPageQueryResultVO; import com.fykj.scaffold.cdo.service.ICdoContactService; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDateTime; // 查询参数类 public class CdoContactParams extends BaseParams { @MatchType(value = QueryType.LIKE, fieldName = {"title", "content"}) @ApiModelProperty(value = "关键词") private String keyword; @MatchType(value = QueryType.EQ) @ApiModelProperty(value = "类型") private String type; @MatchType(value = QueryType.RANGE) @ApiModelProperty(value = "创建时间开始") private LocalDateTime createTimeStart; @MatchType(value = QueryType.RANGE) @ApiModelProperty(value = "创建时间结束") private LocalDateTime createTimeEnd; } // Controller层实现 @RestController @RequestMapping("/admin/contact") public class CdoContactController { @Autowired private ICdoContactService baseService; @ApiOperation("分页查询") @PostMapping("/pageQuery") public Result pageQuery(@RequestBody CdoContactParams params) { IPage result = baseService.page(params).convert(it -> { CdoContactPageQueryResultVO record = new CdoContactPageQueryResultVO(); BeanUtils.copyProperties(it, record); return record; }); // 数据字典转换和脱敏处理 DataConvertUtil.trans(result.getRecords()); return new JsonResult<>(result); } } ``` -------------------------------- ### Java - 多表联合查询 ServiceImpl Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/crud ServiceImpl 层实现了 `momentPages` 方法,创建 `Page` 对象并调用 `baseMapper.momentPages` 方法执行实际的数据库查询。 ```java @Override public IPage momentPages(CdoWorkMomentParams params) { IPage page = new Page<>(params.getCurrentPage(), params.getPageSize()); return baseMapper.momentPages(page, params); } ``` -------------------------------- ### Java - 多表联合查询 Service 接口 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/crud Service 层接口定义了多表联合分页查询的方法 `momentPages`,接收 `CdoWorkMomentParams` 作为查询参数,并返回 `IPage`。 ```java /** * 分页查询 * * @param params 参数 * @return 分页结果 */ IPage momentPages(CdoWorkMomentParams params); ``` -------------------------------- ### JSON Response for Failed Import Source: https://szzf.cnsaas.com/scaffold-boot-docs/sample/excel-import Example JSON structure for a failed Excel data import. It indicates failure, the number of successful and failed items, and the URL to download the failure report. ```json { "success": false, "successCount": 5, "failureCount": 5, "failFileUrl": "URL地址" } ``` -------------------------------- ### Java: Controller调用Excel导出方法(无模板) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/excel 在Controller层调用`ExcelUtil.writeExcelToResponse()`方法,实现无模板Excel的导出。此方法可直接将Excel写入HTTP响应输出流,方便用户下载。需传入要导出的数据列表、文件名及实体类。 ```java @GetMapping(value = "/writeExcel", produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") public void writeExcel() { ExcelUtil.writeExcelToResponse(createMockList(), "下载文件名称", DemoExcelDto.class); } ``` -------------------------------- ### Modify Nginx Repository for CGlib Issue (Shell) Source: https://szzf.cnsaas.com/scaffold-boot-docs/localization/kylin-v10 Instructions to edit the Nginx repository configuration file to resolve CGlib version conflicts. It involves changing the `$releasever` variable to '8'. ```shell vi /etc/yum.repos.d/nginx.repo Change $releasever to 8 ``` -------------------------------- ### 短信验证码登录接口定义 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security 定义了短信验证码登录接口的契约,表明了该登录方式需要的参数:客户端、手机号和短信验证码。 ```java /** * 短信验证码登录 * @param client 客户端 * @param mobile 手机号 * @param smsCode 短信验证码 */ SaTokenInfo smsLogin(String client, String mobile, String smsCode); ``` -------------------------------- ### Code Generator Configuration and Usage (Properties) Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt This snippet shows the configuration properties for a code generator that automatically creates backend (Controller to Mapper) and frontend (Vue) code from database tables. It outlines the necessary setup and steps for using the generator. ```properties // 代码生成器配置 - generation.properties // # 作者 // author=开发者姓名 // # 模块名称 // moduleName=system // # 包名 // packageName=com.fykj.scaffold // # 表前缀(生成代码时会去除) // tablePrefix=sys_ ``` -------------------------------- ### 协议设置 API (Java) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 提供根据编码获取协议内容的功能,用于管理用户协议、隐私政策等。依赖于 `IContentService`。输入为内容编码 `code`,输出为 `Content` 对象。 ```java @RestController @RequestMapping("/api/content") @Api(tags = "协议设置api") public class ContentApi { @Autowired private IContentService contentService; // 手机、PC端根据编码获取内容,接口如下 @GetMapping(value = "/getByCode") @ApiOperation("根据编码获取内容") public JsonResult getByCode(String code) { return new JsonResult<>(contentService.getByCode(code)); } } ``` -------------------------------- ### Controller Parameter Handling with @RequestParam (Java) Source: https://szzf.cnsaas.com/scaffold-boot-docs/rule/get-started Illustrates using `@RequestParam` in a Spring Boot controller for handling single parameters with GET requests. It suggests limiting the number of `@RequestParam` parameters to three, recommending `@RequestBody` for more complex scenarios. ```java @GetMapping("/method") // Recommended not to exceed 3 parameters, consider using @RequestBody for more public Result method(@RequestParam Long id, @RequestParam String name) { return Result.OK(); } ``` -------------------------------- ### Perform CRUD Operations with MyBatis-Plus in Java Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt This snippet demonstrates how to perform single and batch Create, Read, Update, and Delete operations using MyBatis-Plus. It includes examples for saving, updating, deleting, and retrieving entities, with support for transactional operations. Dependencies include MyBatis-Plus and Spring Transactional annotations. ```java import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @Service @Transactional(rollbackFor = Exception.class) public class CdoTaskSignServiceImpl extends BaseServiceImpl implements ICdoTaskSignService { // 新增单个对象 @Override public void saveActivity(CdoTaskSign entity) { entity.setPublishDate(LocalDate.now()); entity.setStatus("draft"); save(entity); } // 批量新增 @Override public void batchSave(List entityList) { saveBatch(entityList); } // 修改对象 @Override public void updateActivity(CdoTaskSign entity) { entity.setUpdateTime(LocalDateTime.now()); updateById(entity); } // 链式更新 @Override public void updateStatus(Long id, String status) { lambdaUpdate() .eq(CdoTaskSign::getId, id) .set(CdoTaskSign::getStatus, status) .set(CdoTaskSign::getUpdateTime, LocalDateTime.now()) .update(); } // 删除数据(含级联删除) @Override public void removeCourse(Long courseId) { // 删除课程 removeById(courseId); // 级联删除关联的考试记录 testService.lambdaUpdate() .eq(CdoTest::getCourseId, courseId) .remove(); } // 查询单个详情 @Override public CdoTaskSignDetailResultVO getActivityDetail(Long id) { CdoTaskSign entity = getById(id); CdoTaskSignDetailResultVO result = new CdoTaskSignDetailResultVO(); BeanUtils.copyProperties(entity, result); DictTransUtil.trans(result); return result; } } ``` -------------------------------- ### 微信公众号配置与接口调用 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/wechat 展示了微信公众号的 AppID 和密钥配置,以及通过 `WxMpService` 获取 JS 签名的 Java 代码示例。需要配置 `wx.mp` 属性,并注入 `WxMpService`。 ```properties wx: mp: appid: APPID secret: 密钥 ``` ```java @Autowired private WxMpService wxService; //例:获取签名 WxJsapiSignature jsapiSignature = wxService.createJsapiSignature(url); ``` -------------------------------- ### XML - 多表联合查询 SQL Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/crud XML 配置文件中定义了 `momentPages` 方法对应的 SQL 语句,实现了多表查询,并根据 `params.title` 条件进行过滤。 ```xml ``` -------------------------------- ### Throw BusinessException in Java Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/exception Demonstrates how to throw a BusinessException with predefined ResultCode or custom error codes. It emphasizes avoiding ResultCode.OK or 0 for error scenarios to prevent misinterpretation as success by the global exception handler. Includes an example of a well-handled business logic flow and a poorly handled one using boolean returns. ```java // Throwing with ResultCode throw new BusinessException(ResultCode.FAIL, "Specific error message"); // Throwing with custom code throw new BusinessException(-2, "Specific error message"); // Good example of using BusinessException public void exchange(Goods entity) { // ... business logic ... int stock = goodsService.queryStockNum(entity.getGoodsId()); if (stock < 1) { throw new BusinessException(ResultCode.FAIL, "Insufficient stock"); } BigDecimal balance = balanceService.queryBalance(entity.getUserId()); if (balance.compareTo(entity.getPrice()) < 0) { throw new BusinessException(ResultCode.FAIL, "Insufficient balance"); } exchangeRecordService.save(entity); } // Bad example using boolean return public boolean exchangeVeryBadCase(Goods entity) { // ... business logic ... int stock = goodsService.queryStockNum(entity.getGoodsId()); if (stock < 1) { return false; // Ambiguous } BigDecimal balance = balanceService.queryBalance(entity.getUserId()); if (balance.compareTo(entity.getPrice()) < 0) { return false; // Ambiguous } exchangeRecordService.save(entity); return true; } ``` -------------------------------- ### 栏位管理 API (Java) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 提供根据父编码获取栏位数据(包括子栏位和级联格式)的功能。主要用于配置项目的导航栏,支持树形结构展示,可设置排序、图标和跳转链接。依赖于 `IColumnService`。输入为栏位编码 `code`,输出为栏位列表或级联数据。 ```java @RestController @RequestMapping("/api/column") @Api(tags = "栏位管理api") public class ColumnApi { @Autowired private IColumnService columnService; // 手机、PC端根据父编码获取第一级栏位的数据 @GetMapping(value = "/getChildColumnList") @ApiOperation("获取子栏位") public JsonResult> getChildColumnList(@RequestParam String code) { return new JsonResult<>(columnService.getChildColumnList(code)); } // 手机、PC端根据父编码下所有栏位的数据,返回格式为树形接口 @GetMapping("/cascadeByCode") @ApiOperation("获取级联") public JsonResult> cascadeByCode(@RequestParam String code) { return new JsonResult<>(columnService.cascadeByCode(code)); } } ``` -------------------------------- ### 协议设置 API Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 用于配置项目中的用户协议、隐私政策等内容,并提供根据编码获取内容详情的接口。 ```APIDOC ## GET /api/content/getByCode ### Description 根据内容的编码获取具体的协议或政策内容。 ### Method GET ### Endpoint /api/content/getByCode ### Parameters #### Query Parameters - **code** (String) - Required - 内容的编码 ### Response #### Success Response (200) - **data** (Content) - 内容对象 - **msg** (String) - 消息 - **code** (Integer) - 状态码 ``` -------------------------------- ### Code Generator Usage Steps and Generated Code Overview Source: https://context7.com/context7/szzf_cnsaas_scaffold-boot-docs/llms.txt This section details the step-by-step process for using the code generator, from database table creation to downloading the generated code. It also lists the types of code generated, including backend components and Vue pages. ```markdown // 使用代码生成器的步骤: // 1. 在数据库中创建表,并添加字段注释 // 2. 访问 http://localhost:9090/doc.html 打开接口文档 // 3. 进入"系统管理 -> 代码生成"模块 // 4. 搜索表名,点击"代码生成"按钮 // 5. 配置生成选项: // - 字段注释: 控制页面显示的中文名称 // - 列表展示: 勾选在列表页显示的字段 // - 详情展示: 勾选在详情页显示的字段 // - 表单展示: 勾选在编辑页显示的字段 // - 查询条件: 选择查询方式(完全匹配/模糊匹配/范围查询) // - 字典配置: 标记字典字段并选择对应字典 // - 必填配置: 勾选表单必填字段 // 6. 点击"生成代码"下载zip包 // 7. 解压后将代码复制到项目对应目录 // 生成的代码包含: // - Controller: 分页查询、详情查询、新增、修改、删除接口 // - Service和ServiceImpl: 业务逻辑层 // - Mapper和XML: 数据访问层 // - Entity: 数据库实体类 // - VO: 页面查询结果类 // - Params: 查询参数类 // - Vue页面: 列表页、详情页、编辑表单 ``` -------------------------------- ### Knife4j Swagger 文档分组配置 (YAML) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/knife4j 在`knife4j.yml`文件中配置Knife4j Swagger文档的分组。可以为不同的业务模块(如积分商城、场馆、活动)设置名称、匹配规则和资源路径,以在接口文档中进行分类展示。 ```yaml knife4j: openapi: title: 接口文档 group: point: group-name: 积分商城 api-rule: package api-rule-resources: - com.fykj.scaffold.point venue: group-name: 场馆 api-rule: package api-rule-resources: - com.fykj.scaffold.venue activity: group-name: 活动 api-rule: package api-rule-resources: - com.fykj.scaffold.activity ``` -------------------------------- ### Java: Controller调用Excel导出方法(按模板) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/excel 在Controller层调用`ExcelUtil.fillExcelToResponse()`方法,实现按模板导出Excel。此方法读取指定模板文件,填充数据后导出。需传入数据列表、文件名、模板名称及实体类。模板文件需放置在`/resources/data/excelTemplate`目录下。 ```java @ApiOperation(value = "填充excel") @GetMapping("/fillExcel") public void fillExcel() { ExcelUtil.fillExcelToResponse(createMockList(), "下载文件名称", "模板名称.xlsx", DemoExcelDto.class); } ``` -------------------------------- ### 获取登录用户信息接口 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security 提供一个接口用于获取当前登录用户的详细信息。这个接口由于历史原因被放置在 UserController 中,并依赖 Oauth2Util 工具类。 ```java @GetMapping("/loginUser") public JsonResult loginUser() { return new JsonResult<>(Oauth2Util.getUser()); } ``` -------------------------------- ### Java - 单表分页查询 Controller Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/crud Controller 层实现单表分页查询,通过 `baseService.page(params)` 方法执行查询,并利用 `convert` 方法将结果转换为指定的 VO 对象。`DataConvertUtil.trans` 用于数据转换。 ```java @ApiOperation("分页查询") @PostMapping("/pageQuery") public Result pageQuery(@RequestBody CdoContactParams params) { IPage result = baseService.page(params).convert(it -> { CdoContactPageQueryResultVO record = new CdoContactPageQueryResultVO(); BeanUtils.copyProperties(it, record); return record; }); DataConvertUtil.trans(result.getRecords()); return new JsonResult<>(result); } ``` -------------------------------- ### Java: 使用 DictTransUtil 进行数据字典转换 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/dict 通过 `DictTransUtil.trans(result)` 方法对单个对象或集合中的数据字典字段进行中文转换。此方法会根据注解配置自动完成转换。 ```java @ApiOperation("账单分页查询") @PostMapping("/pageQuery") public Result pageQuery(@RequestBody(required = false) BlBillInfoParams params) { if (params == null) { params = new BlBillInfoParams(); } IPage result = baseService.pageQuery(params); // 转换数据字典 DictTransUtil.trans(result.getRecords()); return new JsonResult<>(result); } ``` -------------------------------- ### 频道设置 API Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 用于配置小程序、网页等快捷入口,并提供根据频道类型获取频道信息列表的接口。 ```APIDOC ## GET /api/channel/getChannelList ### Description 根据指定的频道类型获取对应的频道信息列表,用于在不同端展示快捷入口。 ### Method GET ### Endpoint /api/channel/getChannelList ### Parameters #### Query Parameters - **type** (String) - Required - 频道类型 (例如: 'MINI_PROGRAM', 'PC') ### Response #### Success Response (200) - **data** (List) - 频道信息列表 - **msg** (String) - 消息 - **code** (Integer) - 状态码 ``` -------------------------------- ### SaToken 登录核心方法 Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/security SaToken 框架提供的核心登录方法,用于生成 Token。在实际业务中,通常会对其进行二次封装以集成更多逻辑。 ```java StpUtil.login(username, client); ``` -------------------------------- ### Java 系统常量类示例 - Scaffold-Boot Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/structure 这是一个 Java 示例,展示了如何在 Scaffold-Boot 框架中定义系统常量。它使用了 `@UtilityClass` 注解来防止实例化,并按用途细分了内部类。此类常用于存储配置类型和组织架构等信息。 ```java /** * 系统常量类 */ @UtilityClass public class SystemCons { /** * 配置类型 */ public static class ConfigType { public static final String STRING = "String"; public static final String INTEGER = "Integer"; public static final String BOOLEAN = "Boolean"; public static final String DECIMAL = "Decimal"; } /** * 组织架构 */ public static class Org { public static final String CDO = "CDO"; } } ``` -------------------------------- ### 配置接口限流 - Java Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/req-limit 通过 `@RateLimit` 注解配置接口限流。该注解可以指定限流周期(cycle)和允许的最大请求次数(count)。超过次数后,将返回自定义的错误消息(msg)。 ```java @ApiOperation("用户登录") @PostMapping(value = "/login") @RateLimit(cycle = 10, count = 5) public Result login(@RequestBody @Validated PasswordLoginDto dto) { //业务逻辑,略... return Result.OK(); } ``` ```java @RateLimit(cycle = 10, count = 5, msg = "登录频率过高,请稍后再试") ``` -------------------------------- ### 频道管理 API (Java) Source: https://szzf.cnsaas.com/scaffold-boot-docs/basic/cms 提供根据频道类型获取频道信息的功能,用于配置小程序、网页的快捷入口。依赖于 `IChannelService`。输入为频道类型 `type`,输出为频道列表。 ```java @RestController @RequestMapping("/api/channel") @Api(tags = "频道管理api") public class ChannelApi { @Autowired private IChannelService channelService; // 手机、PC端根据类型获取频道信息,接口如下 @GetMapping(value = "/getChannelList") @ApiOperation("获取频道信息") public JsonResult> getChannelList(@RequestParam String type) { return new JsonResult<>(channelService.getChannelList(type)); } } ```