Browse Source

返回对象

chengpeng 5 years ago
parent
commit
6856d08a47

+ 8 - 0
mec-education/pom.xml

@@ -83,6 +83,14 @@
 			<version>5.1.9.RELEASE</version>
 			<scope>compile</scope>
 		</dependency>
+        <dependency>
+            <groupId>javax.persistence</groupId>
+            <artifactId>javax.persistence-api</artifactId>
+        </dependency>
+		<dependency>
+			<groupId>javax.persistence</groupId>
+			<artifactId>javax.persistence-api</artifactId>
+		</dependency>
 
 	</dependencies>
 	<build>

+ 31 - 0
mec-education/src/main/java/com/ym/mec/education/base/BaseResponse.java

@@ -0,0 +1,31 @@
+package com.ym.mec.education.base;
+
+import javax.persistence.MappedSuperclass;
+import java.io.Serializable;
+
+/**
+ * @author : chengp
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月25日 17:53
+ */
+@MappedSuperclass
+public class BaseResponse<T> extends Response implements Serializable {
+    protected T dataInfo;
+
+    public BaseResponse() {
+    }
+
+    public T getDataInfo() {
+        return this.dataInfo;
+    }
+
+    public void setDataInfo(final T dataInfo) {
+        this.dataInfo = dataInfo;
+    }
+
+    @Override
+    public String toString() {
+        return "BaseResponse(super=" + super.toString() + ", dataInfo=" + this.getDataInfo() + ")";
+    }
+}

+ 168 - 0
mec-education/src/main/java/com/ym/mec/education/base/PageResponse.java

@@ -0,0 +1,168 @@
+package com.ym.mec.education.base;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月25日 17:53
+ */
+public class PageResponse<T> extends Response implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private List<T> records;
+    private Integer total;
+    private Integer size;
+    private Integer pages;
+    private Integer current;
+    private boolean searchCount;
+    private boolean optimizeCount;
+    private String orderByField;
+    private boolean isAsc;
+
+    public PageResponse() {
+        this.records = Collections.emptyList();
+        this.size = 10;
+        this.current = 1;
+        this.searchCount = true;
+        this.optimizeCount = false;
+        this.isAsc = true;
+    }
+
+    public PageResponse(Integer current, Integer size) {
+        this(current, size, true);
+    }
+
+    public PageResponse(Integer current, Integer size, String orderByField) {
+        this.records = Collections.emptyList();
+        this.setOrderByField(orderByField);
+    }
+
+    public PageResponse(Integer current, Integer size, boolean searchCount) {
+        this.records = Collections.emptyList();
+        this.size = 10;
+        this.current = 1;
+        this.searchCount = true;
+        this.optimizeCount = false;
+        this.isAsc = true;
+        if (current > 1) {
+            this.current = current;
+        }
+
+        this.size = size;
+        this.searchCount = searchCount;
+    }
+
+    public List<T> getRecords() {
+        return this.records;
+    }
+
+    public void setRecords(List<T> records) {
+        this.records = records;
+    }
+
+    protected static Integer offsetCurrent(Integer current, Integer size) {
+        return current > 0 ? (current - 1) * size : 0;
+    }
+
+    public Integer getOffsetCurrent() {
+        return offsetCurrent(this.current, this.size);
+    }
+
+    public boolean hasPrevious() {
+        return this.current > 1;
+    }
+
+    public boolean hasNext() {
+        return this.current < this.pages;
+    }
+
+    public Integer getTotal() {
+        return this.total;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
+
+    public Integer getSize() {
+        return this.size;
+    }
+
+    public void setSize(Integer size) {
+        this.size = size;
+    }
+
+    public Integer getPages() {
+        if (this.size != null && 0 != this.size && this.total != null) {
+            this.pages = this.total / this.size;
+            if (this.total % this.size != 0) {
+                this.pages = this.pages + 1;
+            }
+
+            return this.pages;
+        } else {
+            return null;
+        }
+    }
+
+    public void setCurrent(Integer current) {
+        this.current = current;
+    }
+
+    public Integer getCurrent() {
+        return this.current;
+    }
+
+    public boolean isSearchCount() {
+        return this.searchCount;
+    }
+
+    public void setSearchCount(boolean searchCount) {
+        this.searchCount = searchCount;
+    }
+
+    public boolean isOptimizeCount() {
+        return this.optimizeCount;
+    }
+
+    public void setOptimizeCount(boolean optimizeCount) {
+        this.optimizeCount = optimizeCount;
+    }
+
+    public String getOrderByField() {
+        return this.orderByField;
+    }
+
+    public void setOrderByField(String orderByField) {
+        if (StringUtils.isNotEmpty(orderByField)) {
+            this.orderByField = orderByField;
+        }
+
+    }
+
+    public boolean isAsc() {
+        return this.isAsc;
+    }
+
+    public void setAsc(boolean isAsc) {
+        this.isAsc = isAsc;
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer pg = new StringBuffer();
+        pg.append(" Page:{ [").append(super.toString()).append("], ");
+        if (this.records != null) {
+            pg.append("records-size:").append(this.records.size());
+        } else {
+            pg.append("records is null");
+        }
+
+        return pg.append(" }").toString();
+    }
+
+}

+ 100 - 0
mec-education/src/main/java/com/ym/mec/education/base/Response.java

@@ -0,0 +1,100 @@
+package com.ym.mec.education.base;
+
+/**
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月25日 17:50
+ */
+import java.io.Serializable;
+
+public class Response implements Serializable {
+    protected Integer returnCode;
+    protected String message;
+    protected String chainId;
+
+    public Response() {
+    }
+
+    public Integer getReturnCode() {
+        return this.returnCode;
+    }
+
+    public String getMessage() {
+        return this.message;
+    }
+
+    public String getChainId() {
+        return this.chainId;
+    }
+
+    public void setReturnCode(final Integer returnCode) {
+        this.returnCode = returnCode;
+    }
+
+    public void setMessage(final String message) {
+        this.message = message;
+    }
+
+    public void setChainId(final String chainId) {
+        this.chainId = chainId;
+    }
+    @Override
+    public boolean equals(final Object o) {
+        if (o == this) {
+            return true;
+        } else if (!(o instanceof Response)) {
+            return false;
+        } else {
+            Response other = (Response) o;
+            if (!other.canEqual(this)) {
+                return false;
+            } else {
+                label47:
+                {
+                    Object this$returnCode = this.getReturnCode();
+                    Object other$returnCode = other.getReturnCode();
+                    if (this$returnCode == null) {
+                        if (other$returnCode == null) {
+                            break label47;
+                        }
+                    } else if (this$returnCode.equals(other$returnCode)) {
+                        break label47;
+                    }
+
+                    return false;
+                }
+
+                Object this$message = this.getMessage();
+                Object other$message = other.getMessage();
+                if (this$message == null) {
+                    if (other$message != null) {
+                        return false;
+                    }
+                } else if (!this$message.equals(other$message)) {
+                    return false;
+                }
+
+                Object this$chainId = this.getChainId();
+                Object other$chainId = other.getChainId();
+                if (this$chainId == null) {
+                    if (other$chainId != null) {
+                        return false;
+                    }
+                } else if (!this$chainId.equals(other$chainId)) {
+                    return false;
+                }
+
+                return true;
+            }
+        }
+    }
+
+    protected boolean canEqual(final Object other) {
+        return other instanceof Response;
+    }
+
+    @Override
+    public String toString() {
+        return "Response(returnCode=" + this.getReturnCode() + ", message=" + this.getMessage() + ", chainId=" + this.getChainId() + ")";
+    }
+}

+ 38 - 0
mec-education/src/main/java/com/ym/mec/education/controller/MusicGroupController.java

@@ -0,0 +1,38 @@
+package com.ym.mec.education.controller;
+
+import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
+import com.ym.mec.education.base.BaseResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.persistence.GenerationType;
+
+/**
+ * @author : chengp
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月25日 17:39
+ */
+@RestController(value = "musicGroup")
+@DefaultProperties(defaultFallback = "defaultFallback")
+@Slf4j
+public class MusicGroupController {
+    /**
+     * 服务降级处理
+     *
+     * @return
+     */
+    private BaseResponse defaultFallback() {
+        BaseResponse response = new BaseResponse();
+        response.setReturnCode(500);
+        response.setMessage("太拥挤了, 请稍后再试!");
+        return response;
+    }
+
+    @GetMapping(value = "/say")
+    public String say(){
+
+        return  "utyrewertyu";
+    }
+}

+ 2 - 1
mec-education/src/main/resources/application.yml

@@ -5,7 +5,8 @@ eureka:
   client:
     serviceUrl:
       defaultZone: http://admin:admin123@localhost:8761/eureka/eureka/
-
+      register-with-eureka: false #是否将自己注册到Eureka Server上,默认为true
+      fetch-registry: false #是否从Eureka Server上获取注册信息,默认为true
 spring:
   application:
     name: education-server