WXF 3 anos atrás
pai
commit
a26d282ab9

+ 2 - 2
api-common/src/main/java/api/common/pojo/common/PageVO.java

@@ -10,8 +10,8 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 public class PageVO {
     @JsonInclude(JsonInclude.Include.NON_NULL)
-    private Integer pageNum;
+    private Integer pageNum=1;
     @JsonInclude(JsonInclude.Include.NON_NULL)
-    private Integer pageSize;
+    private Integer pageSize=10;
 
 }

+ 10 - 0
api-common/src/main/java/api/common/pojo/param/demo/TestPageParam.java

@@ -0,0 +1,10 @@
+package api.common.pojo.param.demo;
+
+import api.common.pojo.common.PageVO;
+import lombok.Data;
+
+@Data
+public class TestPageParam extends PageVO {
+
+    private String name;
+}

+ 12 - 0
api-common/src/main/java/api/common/pojo/vo/demo/TestVO.java

@@ -0,0 +1,12 @@
+package api.common.pojo.vo.demo;
+
+import lombok.Data;
+
+@Data
+public class TestVO {
+
+    private String id;
+    private String name;
+    private int age;
+
+}

+ 1 - 0
pom.xml

@@ -16,6 +16,7 @@
         <module>simulation-oauth-server</module>
         <module>simulation-oauth-client</module>
         <module>simulation-resource-scheduler</module>
+        <module>simulation-resource-server</module>
         <module>api-common</module>
         <module>simulation-resource-common</module>
     </modules>

+ 12 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/Application.java

@@ -0,0 +1,12 @@
+package com.css.simulation.resource;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}

+ 21 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/common/utils/PageUtil.java

@@ -0,0 +1,21 @@
+package com.css.simulation.resource.common.utils;
+
+import api.common.pojo.common.PageVO;
+import com.github.pagehelper.PageHelper;
+
+/**
+ * 分页工具类
+ */
+public class PageUtil {
+
+    /**
+     * 统一设置分页参数
+     * @param param
+     */
+    public static void setPageInfo(Object param){
+        if(param != null && param instanceof PageVO) {
+            PageVO pagevo = (PageVO) param;
+            PageHelper.startPage(pagevo.getPageNum(), pagevo.getPageSize());
+        }
+    }
+}

+ 28 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/demo/ctrl/TestCtrl.java

@@ -0,0 +1,28 @@
+package com.css.simulation.resource.demo.ctrl;
+
+import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import com.css.simulation.resource.demo.service.TestService;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping("/test")
+public class TestCtrl {
+
+    @Autowired
+    TestService testService;
+
+    @RequestMapping("getTestPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<TestVO>> getTestPageList(@RequestBody TestPageParam pageParam){
+        ResponseBodyVO<PageInfo<TestVO>> response = new ResponseBodyVO<PageInfo<TestVO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(testService.getTestPageList(pageParam));
+        return response;
+    }
+}

+ 17 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/demo/mapper/TestMapper.java

@@ -0,0 +1,17 @@
+package com.css.simulation.resource.demo.mapper;
+
+
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface TestMapper {
+
+    List<TestVO> getTestPageList(TestPageParam params);
+
+}

+ 24 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/demo/service/TestService.java

@@ -0,0 +1,24 @@
+package com.css.simulation.resource.demo.service;
+
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import com.css.simulation.resource.common.utils.PageUtil;
+import com.css.simulation.resource.demo.mapper.TestMapper;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class TestService {
+
+    @Autowired
+    TestMapper testMapper;
+
+    public PageInfo<TestVO> getTestPageList(TestPageParam params) {
+        PageUtil.setPageInfo(params);
+        List<TestVO> list = testMapper.getTestPageList(params);
+        return new PageInfo<>(list);
+    }
+}

+ 32 - 0
simulation-resource-server/src/main/resources/bootstrap.yaml

@@ -0,0 +1,32 @@
+server:
+  port: 7003
+  servlet:
+    context-path: /simulation/resource/server
+
+spring:
+  application:
+    name: simulation-resource-server
+  #* -------------------------------- 环境配置 --------------------------------
+  profiles:
+    active: dev
+  #* -------------------------------- 微服务配置 --------------------------------
+  cloud:
+    nacos:
+      discovery:
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+      config:
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+        file-extension: yaml
+# 分页插件配置
+pagehelper:
+  helperDialect: mysql
+  reasonable: true
+  supportMethodsArguments: true
+  params: count=countSql
+
+mybatis:
+  mapper-locations: classpath:/mapper/*/*.xml
+  configuration:
+    map-underscore-to-camel-case: true