diff --git a/src/main/java/com/power/doc/controller/CustomHandlerUserController.java b/src/main/java/com/power/doc/controller/CustomHandlerUserController.java new file mode 100644 index 0000000..e0741e0 --- /dev/null +++ b/src/main/java/com/power/doc/controller/CustomHandlerUserController.java @@ -0,0 +1,15 @@ +package com.power.doc.controller; + +import com.power.doc.controller.parent.BaseCustomHandlerController; +import com.power.doc.service.CustomHandlerUserService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author yangyang + * @date 2023/4/23 + */ +@RestController +@RequestMapping("/customHandler/user") +public class CustomHandlerUserController extends BaseCustomHandlerController { +} diff --git a/src/main/java/com/power/doc/controller/CustomHandlerUserRoleController.java b/src/main/java/com/power/doc/controller/CustomHandlerUserRoleController.java new file mode 100644 index 0000000..7e40d4f --- /dev/null +++ b/src/main/java/com/power/doc/controller/CustomHandlerUserRoleController.java @@ -0,0 +1,15 @@ +package com.power.doc.controller; + +import com.power.doc.controller.parent.BaseCustomHandlerController; +import com.power.doc.service.CustomHandlerUserRoleService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author yangyang + * @date 2023/4/23 + */ +@RestController +@RequestMapping("/customHandler/userRole") +public class CustomHandlerUserRoleController extends BaseCustomHandlerController { +} diff --git a/src/main/java/com/power/doc/controller/parent/BaseCustomHandlerController.java b/src/main/java/com/power/doc/controller/parent/BaseCustomHandlerController.java new file mode 100644 index 0000000..c6e99df --- /dev/null +++ b/src/main/java/com/power/doc/controller/parent/BaseCustomHandlerController.java @@ -0,0 +1,43 @@ +package com.power.doc.controller.parent; + +import com.power.doc.entity.XbootBaseEntity; +import com.power.doc.service.BaseCustomHandlerService; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +import java.util.List; + +/** + * 基础Controller,提供通用curd方法 + * + * @author yangyang + * @date 2023/4/23 + */ +public abstract class BaseCustomHandlerController { + @Autowired + private T service; + + /** + * 查询列表 + * @return + */ + @GetMapping() + public List findList() { + return service.findList(); + } + + /** + * 创建实例 + * @param request + */ + @PostMapping() + public void create(HttpServletRequest request) { + XbootBaseEntity t = service.newEntity(); + /** + * 通过request中的数据信息进行绑定 + */ + service.create(t); + } +} diff --git a/src/main/java/com/power/doc/service/BaseCustomHandlerService.java b/src/main/java/com/power/doc/service/BaseCustomHandlerService.java new file mode 100644 index 0000000..ab70539 --- /dev/null +++ b/src/main/java/com/power/doc/service/BaseCustomHandlerService.java @@ -0,0 +1,57 @@ +package com.power.doc.service; + +import com.power.doc.entity.XbootBaseEntity; +import jakarta.annotation.PostConstruct; + +import java.lang.reflect.ParameterizedType; +import java.util.ArrayList; +import java.util.List; + +/** + * 基础Service,提供通用curd方法 + * 此处泛型值传递T,即Entity信息,实际场景中传递的泛型要更多 + * + * @author yangyang + * @date 2023/4/23 + */ +public abstract class BaseCustomHandlerService { + private Class entityClass; + + /** + * 构造函数,获取类型信息 + */ + @PostConstruct + public void init() { + entityClass = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + } + + /** + * 查询列表 + * + * @return + */ + public List findList() { + return new ArrayList<>(); + } + + /** + * 创建 + * + * @param entity + */ + public void create(T entity) { + + } + + public Class getEntityClass() { + return entityClass; + } + + /** + * 通过 T 的类型信息实例化 + * @return + */ + public T newEntity() { + return null; + } +} diff --git a/src/main/java/com/power/doc/service/CustomHandlerUserRoleService.java b/src/main/java/com/power/doc/service/CustomHandlerUserRoleService.java new file mode 100644 index 0000000..fa2235a --- /dev/null +++ b/src/main/java/com/power/doc/service/CustomHandlerUserRoleService.java @@ -0,0 +1,14 @@ +package com.power.doc.service; + +import com.power.doc.entity.UserRole; +import org.springframework.stereotype.Service; + +/** + * 用户角色管理Service + * + * @author yangyang + * @date 2023/4/23 + */ +@Service +public class CustomHandlerUserRoleService extends BaseCustomHandlerService { +} diff --git a/src/main/java/com/power/doc/service/CustomHandlerUserService.java b/src/main/java/com/power/doc/service/CustomHandlerUserService.java new file mode 100644 index 0000000..d637071 --- /dev/null +++ b/src/main/java/com/power/doc/service/CustomHandlerUserService.java @@ -0,0 +1,14 @@ +package com.power.doc.service; + +import com.power.doc.entity.User; +import org.springframework.stereotype.Service; + +/** + * 用户管理Service + * + * @author yangyang + * @date 2023/4/23 + */ +@Service +public class CustomHandlerUserService extends BaseCustomHandlerService { +}