Commit 2aecdbf09ea5654fe3994984fbd9a42a91d5d47d
1 parent
5b9879ca
代码生成:增加主子表 normal 模式的示例
Showing
23 changed files
with
845 additions
and
35 deletions
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
| ... | ... | @@ -66,4 +66,5 @@ public interface ErrorCodeConstants { |
| 66 | 66 | ErrorCode DEMO02_CATEGORY_PARENT_ERROR = new ErrorCode(1_001_201_004, "不能设置自己为父示例分类"); |
| 67 | 67 | ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); |
| 68 | 68 | ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); |
| 69 | + ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); | |
| 69 | 70 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo.demo02; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 6 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 3 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; |
| 4 | 8 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryRespVO; |
| 5 | 9 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; |
| 6 | -import org.springframework.web.bind.annotation.*; | |
| 7 | -import javax.annotation.Resource; | |
| 8 | -import org.springframework.validation.annotation.Validated; | |
| 9 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 10 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.service.demo.demo02.Demo02CategoryService; | |
| 12 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | +import org.springframework.validation.annotation.Validated; | |
| 17 | +import org.springframework.web.bind.annotation.*; | |
| 13 | 18 | |
| 14 | -import javax.validation.*; | |
| 15 | -import javax.servlet.http.*; | |
| 16 | -import java.util.*; | |
| 19 | +import javax.annotation.Resource; | |
| 20 | +import javax.servlet.http.HttpServletResponse; | |
| 21 | +import javax.validation.Valid; | |
| 17 | 22 | import java.io.IOException; |
| 23 | +import java.util.List; | |
| 18 | 24 | |
| 19 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | - | |
| 23 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | - | |
| 25 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | - | |
| 28 | -import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; | |
| 29 | -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; | |
| 30 | -import cn.iocoder.yudao.module.infra.service.demo.demo02.Demo02CategoryService; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 31 | 27 | |
| 32 | 28 | @Tag(name = "管理后台 - 示例分类") |
| 33 | 29 | @RestController | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.*; | |
| 12 | +import javax.servlet.http.*; | |
| 13 | +import java.util.*; | |
| 14 | +import java.io.IOException; | |
| 15 | + | |
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 20 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 21 | + | |
| 22 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 23 | + | |
| 24 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 25 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 26 | + | |
| 27 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; | |
| 28 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService; | |
| 32 | + | |
| 33 | +@Tag(name = "管理后台 - 学生") | |
| 34 | +@RestController | |
| 35 | +@RequestMapping("/infra/demo03-student") | |
| 36 | +@Validated | |
| 37 | +public class Demo03StudentController { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private Demo03StudentService demo03StudentService; | |
| 41 | + | |
| 42 | + @PostMapping("/create") | |
| 43 | + @Operation(summary = "创建学生") | |
| 44 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") | |
| 45 | + public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) { | |
| 46 | + return success(demo03StudentService.createDemo03Student(createReqVO)); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @PutMapping("/update") | |
| 50 | + @Operation(summary = "更新学生") | |
| 51 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") | |
| 52 | + public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) { | |
| 53 | + demo03StudentService.updateDemo03Student(updateReqVO); | |
| 54 | + return success(true); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @DeleteMapping("/delete") | |
| 58 | + @Operation(summary = "删除学生") | |
| 59 | + @Parameter(name = "id", description = "编号", required = true) | |
| 60 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | |
| 61 | + public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) { | |
| 62 | + demo03StudentService.deleteDemo03Student(id); | |
| 63 | + return success(true); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @GetMapping("/get") | |
| 67 | + @Operation(summary = "获得学生") | |
| 68 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 69 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 70 | + public CommonResult<Demo03StudentRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 71 | + Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id); | |
| 72 | + return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class)); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @GetMapping("/page") | |
| 76 | + @Operation(summary = "获得学生分页") | |
| 77 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 78 | + public CommonResult<PageResult<Demo03StudentRespVO>> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) { | |
| 79 | + PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO); | |
| 80 | + return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class)); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @GetMapping("/export-excel") | |
| 84 | + @Operation(summary = "导出学生 Excel") | |
| 85 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") | |
| 86 | + @OperateLog(type = EXPORT) | |
| 87 | + public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, | |
| 88 | + HttpServletResponse response) throws IOException { | |
| 89 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 90 | + List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); | |
| 91 | + // 导出 Excel | |
| 92 | + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, | |
| 93 | + BeanUtils.toBean(list, Demo03StudentRespVO.class)); | |
| 94 | + } | |
| 95 | + | |
| 96 | + // ==================== 子表(学生课程) ==================== | |
| 97 | + | |
| 98 | + @GetMapping("/demo03-course/list-by-student-id") | |
| 99 | + @Operation(summary = "获得学生课程列表") | |
| 100 | + @Parameter(name = "studentId", description = "学生编号") | |
| 101 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 102 | + public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 103 | + return success(demo03StudentService.getDemo03CourseListByStudentId(studentId)); | |
| 104 | + } | |
| 105 | + | |
| 106 | + // ==================== 子表(学生班级) ==================== | |
| 107 | + | |
| 108 | + @GetMapping("/demo03-grade/get-by-student-id") | |
| 109 | + @Operation(summary = "获得学生班级") | |
| 110 | + @Parameter(name = "studentId", description = "学生编号") | |
| 111 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 112 | + public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { | |
| 113 | + return success(demo03StudentService.getDemo03GradeByStudentId(studentId)); | |
| 114 | + } | |
| 115 | + | |
| 116 | +} | |
| 0 | 117 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class Demo03StudentPageReqVO extends PageParam { | |
| 16 | + | |
| 17 | + @Schema(description = "名字", example = "芋艿") | |
| 18 | + private String name; | |
| 19 | + | |
| 20 | + @Schema(description = "性别") | |
| 21 | + private Integer sex; | |
| 22 | + | |
| 23 | + @Schema(description = "简介", example = "随便") | |
| 24 | + private String description; | |
| 25 | + | |
| 26 | + @Schema(description = "创建时间") | |
| 27 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 28 | + private LocalDateTime[] createTime; | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.alibaba.excel.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 9 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 12 | +@Data | |
| 13 | +@ExcelIgnoreUnannotated | |
| 14 | +public class Demo03StudentRespVO { | |
| 15 | + | |
| 16 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 17 | + @ExcelProperty("编号") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 21 | + @ExcelProperty("名字") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 26 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 27 | + private Integer sex; | |
| 28 | + | |
| 29 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 30 | + @ExcelProperty("出生日期") | |
| 31 | + private LocalDateTime birthday; | |
| 32 | + | |
| 33 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 34 | + @ExcelProperty("简介") | |
| 35 | + private String description; | |
| 36 | + | |
| 37 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 38 | + @ExcelProperty("创建时间") | |
| 39 | + private LocalDateTime createTime; | |
| 40 | + | |
| 41 | +} | |
| 0 | 42 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 12 | +@Data | |
| 13 | +public class Demo03StudentSaveReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 19 | + @NotEmpty(message = "名字不能为空") | |
| 20 | + private String name; | |
| 21 | + | |
| 22 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 23 | + @NotNull(message = "性别不能为空") | |
| 24 | + private Integer sex; | |
| 25 | + | |
| 26 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 27 | + @NotNull(message = "出生日期不能为空") | |
| 28 | + private LocalDateTime birthday; | |
| 29 | + | |
| 30 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 31 | + @NotEmpty(message = "简介不能为空") | |
| 32 | + private String description; | |
| 33 | + | |
| 34 | + | |
| 35 | + private List<Demo03CourseDO> demo03Courses; | |
| 36 | + | |
| 37 | + private Demo03GradeDO demo03Grade; | |
| 38 | + | |
| 39 | +} | |
| 0 | 40 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/demo03/Demo03CourseDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生课程 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_demo03_course") | |
| 16 | +@KeySequence("infra_demo03_course_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class Demo03CourseDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 分数 | |
| 40 | + */ | |
| 41 | + private Integer score; | |
| 42 | + | |
| 43 | +} | |
| 0 | 44 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/demo03/Demo03GradeDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班级 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_demo03_grade") | |
| 16 | +@KeySequence("infra_demo03_grade_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class Demo03GradeDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 班主任 | |
| 40 | + */ | |
| 41 | + private String teacher; | |
| 42 | + | |
| 43 | +} | |
| 0 | 44 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/demo03/Demo03StudentDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | +import com.baomidou.mybatisplus.annotation.*; | |
| 9 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 学生 DO | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +@TableName("infra_demo03_student") | |
| 17 | +@KeySequence("infra_demo03_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 18 | +@Data | |
| 19 | +@EqualsAndHashCode(callSuper = true) | |
| 20 | +@ToString(callSuper = true) | |
| 21 | +@Builder | |
| 22 | +@NoArgsConstructor | |
| 23 | +@AllArgsConstructor | |
| 24 | +public class Demo03StudentDO extends BaseDO { | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 编号 | |
| 28 | + */ | |
| 29 | + @TableId | |
| 30 | + private Long id; | |
| 31 | + /** | |
| 32 | + * 名字 | |
| 33 | + */ | |
| 34 | + private String name; | |
| 35 | + /** | |
| 36 | + * 性别 | |
| 37 | + * | |
| 38 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 39 | + */ | |
| 40 | + private Integer sex; | |
| 41 | + /** | |
| 42 | + * 出生日期 | |
| 43 | + */ | |
| 44 | + private LocalDateTime birthday; | |
| 45 | + /** | |
| 46 | + * 简介 | |
| 47 | + */ | |
| 48 | + private String description; | |
| 49 | + | |
| 50 | +} | |
| 0 | 51 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo02/Demo02CategoryMapper.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo02/Demo02CategoryMapper.java
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 7 | +import org.apache.ibatis.annotations.Mapper; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生课程 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { | |
| 16 | + | |
| 17 | + default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | |
| 18 | + return selectList(Demo03CourseDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03CourseDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | +} | |
| 0 | 26 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 学生班级 Mapper | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +@Mapper | |
| 13 | +public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { | |
| 14 | + | |
| 15 | + default Demo03GradeDO selectByStudentId(Long studentId) { | |
| 16 | + return selectOne(Demo03GradeDO::getStudentId, studentId); | |
| 17 | + } | |
| 18 | + | |
| 19 | + default int deleteByStudentId(Long studentId) { | |
| 20 | + return delete(Demo03GradeDO::getStudentId, studentId); | |
| 21 | + } | |
| 22 | + | |
| 23 | +} | |
| 0 | 24 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 7 | +import org.apache.ibatis.annotations.Mapper; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface Demo03StudentMapper extends BaseMapperX<Demo03StudentDO> { | |
| 17 | + | |
| 18 | + default PageResult<Demo03StudentDO> selectPage(Demo03StudentPageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>() | |
| 20 | + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) | |
| 21 | + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) | |
| 22 | + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) | |
| 23 | + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(Demo03StudentDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/package-info.java deleted
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java
| ... | ... | @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 4 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; |
| 7 | -import cn.iocoder.yudao.module.infra.dal.mysql.demo02.Demo02CategoryMapper; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper; | |
| 8 | 8 | import org.springframework.stereotype.Service; |
| 9 | 9 | import org.springframework.validation.annotation.Validated; |
| 10 | 10 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 学生 Service 接口 | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +public interface Demo03StudentService { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 创建学生 | |
| 20 | + * | |
| 21 | + * @param createReqVO 创建信息 | |
| 22 | + * @return 编号 | |
| 23 | + */ | |
| 24 | + Long createDemo03Student(@Valid Demo03StudentSaveReqVO createReqVO); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 更新学生 | |
| 28 | + * | |
| 29 | + * @param updateReqVO 更新信息 | |
| 30 | + */ | |
| 31 | + void updateDemo03Student(@Valid Demo03StudentSaveReqVO updateReqVO); | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 删除学生 | |
| 35 | + * | |
| 36 | + * @param id 编号 | |
| 37 | + */ | |
| 38 | + void deleteDemo03Student(Long id); | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 获得学生 | |
| 42 | + * | |
| 43 | + * @param id 编号 | |
| 44 | + * @return 学生 | |
| 45 | + */ | |
| 46 | + Demo03StudentDO getDemo03Student(Long id); | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 获得学生分页 | |
| 50 | + * | |
| 51 | + * @param pageReqVO 分页查询 | |
| 52 | + * @return 学生分页 | |
| 53 | + */ | |
| 54 | + PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); | |
| 55 | + | |
| 56 | + | |
| 57 | + // ==================== 子表(学生课程) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生课程列表 | |
| 61 | + * | |
| 62 | + * @param studentId 学生编号 | |
| 63 | + * @return 学生课程列表 | |
| 64 | + */ | |
| 65 | + List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | |
| 66 | + | |
| 67 | + | |
| 68 | + // ==================== 子表(学生班级) ==================== | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * 获得学生班级 | |
| 72 | + * | |
| 73 | + * @param studentId 学生编号 | |
| 74 | + * @return 学生班级 | |
| 75 | + */ | |
| 76 | + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | |
| 77 | + | |
| 78 | +} | |
| 0 | 79 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 15 | + | |
| 16 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper; | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper; | |
| 19 | + | |
| 20 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 21 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * 学生 Service 实现类 | |
| 25 | + * | |
| 26 | + * @author 芋道源码 | |
| 27 | + */ | |
| 28 | +@Service | |
| 29 | +@Validated | |
| 30 | +public class Demo03StudentServiceImpl implements Demo03StudentService { | |
| 31 | + | |
| 32 | + @Resource | |
| 33 | + private Demo03StudentMapper demo03StudentMapper; | |
| 34 | + @Resource | |
| 35 | + private Demo03CourseMapper demo03CourseMapper; | |
| 36 | + @Resource | |
| 37 | + private Demo03GradeMapper demo03GradeMapper; | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + @Transactional(rollbackFor = Exception.class) | |
| 41 | + public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { | |
| 42 | + // 插入 | |
| 43 | + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); | |
| 44 | + demo03StudentMapper.insert(demo03Student); | |
| 45 | + | |
| 46 | + // 插入子表 | |
| 47 | + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | |
| 48 | + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | |
| 49 | + // 返回 | |
| 50 | + return demo03Student.getId(); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + @Transactional(rollbackFor = Exception.class) | |
| 55 | + public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { | |
| 56 | + // 校验存在 | |
| 57 | + validateDemo03StudentExists(updateReqVO.getId()); | |
| 58 | + // 更新 | |
| 59 | + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); | |
| 60 | + demo03StudentMapper.updateById(updateObj); | |
| 61 | + | |
| 62 | + // 更新子表 | |
| 63 | + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | |
| 64 | + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + @Transactional(rollbackFor = Exception.class) | |
| 69 | + public void deleteDemo03Student(Long id) { | |
| 70 | + // 校验存在 | |
| 71 | + validateDemo03StudentExists(id); | |
| 72 | + // 删除 | |
| 73 | + demo03StudentMapper.deleteById(id); | |
| 74 | + | |
| 75 | + // 删除子表 | |
| 76 | + deleteDemo03CourseByStudentId(id); | |
| 77 | + deleteDemo03GradeByStudentId(id); | |
| 78 | + } | |
| 79 | + | |
| 80 | + private void validateDemo03StudentExists(Long id) { | |
| 81 | + if (demo03StudentMapper.selectById(id) == null) { | |
| 82 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public Demo03StudentDO getDemo03Student(Long id) { | |
| 88 | + return demo03StudentMapper.selectById(id); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Override | |
| 92 | + public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO) { | |
| 93 | + return demo03StudentMapper.selectPage(pageReqVO); | |
| 94 | + } | |
| 95 | + | |
| 96 | + // ==================== 子表(学生课程) ==================== | |
| 97 | + | |
| 98 | + @Override | |
| 99 | + public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) { | |
| 100 | + return demo03CourseMapper.selectListByStudentId(studentId); | |
| 101 | + } | |
| 102 | + | |
| 103 | + private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 104 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 105 | + demo03CourseMapper.insertBatch(list); | |
| 106 | + } | |
| 107 | + | |
| 108 | + private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 109 | + deleteDemo03CourseByStudentId(studentId); | |
| 110 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 111 | + createDemo03CourseList(studentId, list); | |
| 112 | + } | |
| 113 | + | |
| 114 | + private void deleteDemo03CourseByStudentId(Long studentId) { | |
| 115 | + demo03CourseMapper.deleteByStudentId(studentId); | |
| 116 | + } | |
| 117 | + | |
| 118 | + // ==================== 子表(学生班级) ==================== | |
| 119 | + | |
| 120 | + @Override | |
| 121 | + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | |
| 122 | + return demo03GradeMapper.selectByStudentId(studentId); | |
| 123 | + } | |
| 124 | + | |
| 125 | + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 126 | + if (demo03Grade == null) { | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + demo03Grade.setStudentId(studentId); | |
| 130 | + demo03GradeMapper.insert(demo03Grade); | |
| 131 | + } | |
| 132 | + | |
| 133 | + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 134 | + if (demo03Grade == null) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + demo03Grade.setStudentId(studentId); | |
| 138 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 139 | + demo03GradeMapper.insertOrUpdate(demo03Grade); | |
| 140 | + } | |
| 141 | + | |
| 142 | + private void deleteDemo03GradeByStudentId(Long studentId) { | |
| 143 | + demo03GradeMapper.deleteByStudentId(studentId); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm
| ... | ... | @@ -31,8 +31,9 @@ |
| 31 | 31 | #elseif ($javaType == "Boolean") |
| 32 | 32 | #set ($dictMethod = "getBoolDictOptions") |
| 33 | 33 | #end |
| 34 | - #if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 TODO 芋艿:这里要忽略下 join 字段; | |
| 35 | - <el-table-column label="${comment}" width="150"> | |
| 34 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 35 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 36 | + <el-table-column label="${comment}" min-width="150"> | |
| 36 | 37 | <template #default="{ row, $index }"> |
| 37 | 38 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 38 | 39 | <el-input v-model="row.${javaField}" placeholder="请输入${comment}" /> |
| ... | ... | @@ -40,7 +41,7 @@ |
| 40 | 41 | </template> |
| 41 | 42 | </el-table-column> |
| 42 | 43 | #elseif($column.htmlType == "imageUpload")## 图片上传 |
| 43 | - <el-table-column label="${comment}" width="200"> | |
| 44 | + <el-table-column label="${comment}" min-width="200"> | |
| 44 | 45 | <template #default="{ row, $index }"> |
| 45 | 46 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 46 | 47 | <UploadImg v-model="row.${javaField}" /> |
| ... | ... | @@ -48,7 +49,7 @@ |
| 48 | 49 | </template> |
| 49 | 50 | </el-table-column> |
| 50 | 51 | #elseif($column.htmlType == "fileUpload")## 文件上传 |
| 51 | - <el-table-column label="${comment}" width="200"> | |
| 52 | + <el-table-column label="${comment}" min-width="200"> | |
| 52 | 53 | <template #default="{ row, $index }"> |
| 53 | 54 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 54 | 55 | <UploadFile v-model="row.${javaField}" /> |
| ... | ... | @@ -56,7 +57,7 @@ |
| 56 | 57 | </template> |
| 57 | 58 | </el-table-column> |
| 58 | 59 | #elseif($column.htmlType == "editor")## 文本编辑器 |
| 59 | - <el-table-column label="${comment}" width="400"> | |
| 60 | + <el-table-column label="${comment}" min-width="400"> | |
| 60 | 61 | <template #default="{ row, $index }"> |
| 61 | 62 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 62 | 63 | <Editor v-model="row.${javaField}" height="150px" /> |
| ... | ... | @@ -64,7 +65,7 @@ |
| 64 | 65 | </template> |
| 65 | 66 | </el-table-column> |
| 66 | 67 | #elseif($column.htmlType == "select")## 下拉框 |
| 67 | - <el-table-column label="${comment}" width="150"> | |
| 68 | + <el-table-column label="${comment}" min-width="150"> | |
| 68 | 69 | <template #default="{ row, $index }"> |
| 69 | 70 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 70 | 71 | <el-select v-model="row.${javaField}" placeholder="请选择${comment}"> |
| ... | ... | @@ -83,7 +84,7 @@ |
| 83 | 84 | </template> |
| 84 | 85 | </el-table-column> |
| 85 | 86 | #elseif($column.htmlType == "checkbox")## 多选框 |
| 86 | - <el-table-column label="${comment}" width="150"> | |
| 87 | + <el-table-column label="${comment}" min-width="150"> | |
| 87 | 88 | <template #default="{ row, $index }"> |
| 88 | 89 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 89 | 90 | <el-checkbox-group v-model="row.${javaField}"> |
| ... | ... | @@ -103,7 +104,7 @@ |
| 103 | 104 | </template> |
| 104 | 105 | </el-table-column> |
| 105 | 106 | #elseif($column.htmlType == "radio")## 单选框 |
| 106 | - <el-table-column label="${comment}" width="150"> | |
| 107 | + <el-table-column label="${comment}" min-width="150"> | |
| 107 | 108 | <template #default="{ row, $index }"> |
| 108 | 109 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 109 | 110 | <el-radio-group v-model="row.${javaField}"> |
| ... | ... | @@ -123,7 +124,7 @@ |
| 123 | 124 | </template> |
| 124 | 125 | </el-table-column> |
| 125 | 126 | #elseif($column.htmlType == "datetime")## 时间框 |
| 126 | - <el-table-column label="${comment}" width="150"> | |
| 127 | + <el-table-column label="${comment}" min-width="150"> | |
| 127 | 128 | <template #default="{ row, $index }"> |
| 128 | 129 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 129 | 130 | <el-date-picker |
| ... | ... | @@ -136,7 +137,7 @@ |
| 136 | 137 | </template> |
| 137 | 138 | </el-table-column> |
| 138 | 139 | #elseif($column.htmlType == "textarea")## 文本框 |
| 139 | - <el-table-column label="${comment}" width="200"> | |
| 140 | + <el-table-column label="${comment}" min-width="200"> | |
| 140 | 141 | <template #default="{ row, $index }"> |
| 141 | 142 | <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> |
| 142 | 143 | <el-input v-model="row.${javaField}" type="textarea" placeholder="请输入${comment}" /> |
| ... | ... | @@ -179,7 +180,8 @@ |
| 179 | 180 | #elseif ($javaType == "Boolean") |
| 180 | 181 | #set ($dictMethod = "getBoolDictOptions") |
| 181 | 182 | #end |
| 182 | - #if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 TODO 芋艿:这里要忽略下 join 字段; | |
| 183 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 184 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 183 | 185 | <el-form-item label="${comment}" prop="${javaField}"> |
| 184 | 186 | <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" /> |
| 185 | 187 | </el-form-item> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm
| ... | ... | @@ -243,9 +243,11 @@ import download from '@/utils/download' |
| 243 | 243 | import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}' |
| 244 | 244 | import ${simpleClassName}Form from './${simpleClassName}Form.vue' |
| 245 | 245 | ## 特殊:主子表专属逻辑 |
| 246 | +#if ( $table.templateType != 10 ) | |
| 246 | 247 | #foreach ($subSimpleClassName in $subSimpleClassNames) |
| 247 | 248 | import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue' |
| 248 | 249 | #end |
| 250 | +#end | |
| 249 | 251 | |
| 250 | 252 | defineOptions({ name: '${table.className}' }) |
| 251 | 253 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo02/Demo02CategoryMapper.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 3 | -<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo02.Demo02CategoryMapper"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper"> | |
| 4 | 4 | |
| 5 | 5 | <!-- |
| 6 | 6 | 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo03/Demo03StudentMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo03/Demo03StudentServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo03; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentServiceImpl; | |
| 4 | +import org.junit.jupiter.api.Disabled; | |
| 5 | +import org.junit.jupiter.api.Test; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import org.springframework.context.annotation.Import; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 19 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 21 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 22 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 23 | +import static org.junit.jupiter.api.Assertions.*; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * {@link Demo03StudentServiceImpl} 的单元测试类 | |
| 27 | + * | |
| 28 | + * @author 芋道源码 | |
| 29 | + */ | |
| 30 | +@Import(Demo03StudentServiceImpl.class) | |
| 31 | +public class Demo03StudentServiceImplTest extends BaseDbUnitTest { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private Demo03StudentServiceImpl demo03StudentService; | |
| 35 | + | |
| 36 | + @Resource | |
| 37 | + private Demo03StudentMapper demo03StudentMapper; | |
| 38 | + | |
| 39 | + @Test | |
| 40 | + public void testCreateDemo03Student_success() { | |
| 41 | + // 准备参数 | |
| 42 | + Demo03StudentSaveReqVO createReqVO = randomPojo(Demo03StudentSaveReqVO.class).setId(null); | |
| 43 | + | |
| 44 | + // 调用 | |
| 45 | + Long demo03StudentId = demo03StudentService.createDemo03Student(createReqVO); | |
| 46 | + // 断言 | |
| 47 | + assertNotNull(demo03StudentId); | |
| 48 | + // 校验记录的属性是否正确 | |
| 49 | + Demo03StudentDO demo03Student = demo03StudentMapper.selectById(demo03StudentId); | |
| 50 | + assertPojoEquals(createReqVO, demo03Student, "id"); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Test | |
| 54 | + public void testUpdateDemo03Student_success() { | |
| 55 | + // mock 数据 | |
| 56 | + Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class); | |
| 57 | + demo03StudentMapper.insert(dbDemo03Student);// @Sql: 先插入出一条存在的数据 | |
| 58 | + // 准备参数 | |
| 59 | + Demo03StudentSaveReqVO updateReqVO = randomPojo(Demo03StudentSaveReqVO.class, o -> { | |
| 60 | + o.setId(dbDemo03Student.getId()); // 设置更新的 ID | |
| 61 | + }); | |
| 62 | + | |
| 63 | + // 调用 | |
| 64 | + demo03StudentService.updateDemo03Student(updateReqVO); | |
| 65 | + // 校验是否更新正确 | |
| 66 | + Demo03StudentDO demo03Student = demo03StudentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 67 | + assertPojoEquals(updateReqVO, demo03Student); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Test | |
| 71 | + public void testUpdateDemo03Student_notExists() { | |
| 72 | + // 准备参数 | |
| 73 | + Demo03StudentSaveReqVO updateReqVO = randomPojo(Demo03StudentSaveReqVO.class); | |
| 74 | + | |
| 75 | + // 调用, 并断言异常 | |
| 76 | + assertServiceException(() -> demo03StudentService.updateDemo03Student(updateReqVO), DEMO03_STUDENT_NOT_EXISTS); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Test | |
| 80 | + public void testDeleteDemo03Student_success() { | |
| 81 | + // mock 数据 | |
| 82 | + Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class); | |
| 83 | + demo03StudentMapper.insert(dbDemo03Student);// @Sql: 先插入出一条存在的数据 | |
| 84 | + // 准备参数 | |
| 85 | + Long id = dbDemo03Student.getId(); | |
| 86 | + | |
| 87 | + // 调用 | |
| 88 | + demo03StudentService.deleteDemo03Student(id); | |
| 89 | + // 校验数据不存在了 | |
| 90 | + assertNull(demo03StudentMapper.selectById(id)); | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Test | |
| 94 | + public void testDeleteDemo03Student_notExists() { | |
| 95 | + // 准备参数 | |
| 96 | + Long id = randomLongId(); | |
| 97 | + | |
| 98 | + // 调用, 并断言异常 | |
| 99 | + assertServiceException(() -> demo03StudentService.deleteDemo03Student(id), DEMO03_STUDENT_NOT_EXISTS); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Test | |
| 103 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 104 | + public void testGetDemo03StudentPage() { | |
| 105 | + // mock 数据 | |
| 106 | + Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class, o -> { // 等会查询到 | |
| 107 | + o.setName(null); | |
| 108 | + o.setSex(null); | |
| 109 | + o.setDescription(null); | |
| 110 | + o.setCreateTime(null); | |
| 111 | + }); | |
| 112 | + demo03StudentMapper.insert(dbDemo03Student); | |
| 113 | + // 测试 name 不匹配 | |
| 114 | + demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setName(null))); | |
| 115 | + // 测试 sex 不匹配 | |
| 116 | + demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setSex(null))); | |
| 117 | + // 测试 description 不匹配 | |
| 118 | + demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setDescription(null))); | |
| 119 | + // 测试 createTime 不匹配 | |
| 120 | + demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setCreateTime(null))); | |
| 121 | + // 准备参数 | |
| 122 | + Demo03StudentPageReqVO reqVO = new Demo03StudentPageReqVO(); | |
| 123 | + reqVO.setName(null); | |
| 124 | + reqVO.setSex(null); | |
| 125 | + reqVO.setDescription(null); | |
| 126 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 127 | + | |
| 128 | + // 调用 | |
| 129 | + PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(reqVO); | |
| 130 | + // 断言 | |
| 131 | + assertEquals(1, pageResult.getTotal()); | |
| 132 | + assertEquals(1, pageResult.getList().size()); | |
| 133 | + assertPojoEquals(dbDemo03Student, pageResult.getList().get(0)); | |
| 134 | + } | |
| 135 | + | |
| 136 | +} | |
| 0 | 137 | \ No newline at end of file | ... | ... |