فهرست منبع

20220903 删除了main子模块,对common子模块的build方式进行了规范

lifuquan 2 سال پیش
والد
کامیت
d6a6da5833

+ 27 - 0
common/pom.xml

@@ -31,4 +31,31 @@
         </dependency>
     </dependencies>
 
+    <build>
+        <finalName>common</finalName>
+        <plugins>
+            <!-- 编译插件,用于指定编译java语言版本 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <!-- 指定代码和编译后的java版本 -->
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <!-- 打包插件,用于配置打包参数 -->
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <!-- 把systemPath指定的依赖一起打包到BOOT-INF/lib -->
+                    <includeSystemScope>true</includeSystemScope>
+                    <!-- 打包1个带exec的可执行jar包和一个不带exec的可作为依赖的jar包 -->
+                    <classifier>exec</classifier>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>

+ 12 - 0
common/src/main/java/com/nokia/common/CommonApplication.java

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

+ 62 - 0
common/src/main/java/com/nokia/common/mvc/http/R.java

@@ -1,5 +1,67 @@
 package com.nokia.common.mvc.http;
 
+import lombok.Data;
+
+/**
+ * Http返回值的统一包装
+ */
+@Data
 public class R {
+    private Boolean success;
+    private Integer code;
+    private String message;
+
+    private Object data = null;
+
+    /**
+     * 私有化构造方法,不允许在外部实例化
+     */
+    private R() {
+    }
+
+    /**
+     * 成功的静态方法
+     *
+     * @return R实例
+     */
+    public static R ok() {
+        R r = new R();
+        r.setSuccess(true);
+        r.setCode(200);
+        r.setMessage("成功");
+        return r;
+    }
+
+    /**
+     * 失败的静态方法
+     *
+     * @return R实例
+     */
+    public static R error() {
+        R r = new R();
+        r.setSuccess(false);
+        r.setCode(500);
+        r.setMessage("失败");
+        return r;
+    }
+
+    public R success(Boolean success) {
+        this.setSuccess(success);
+        return this;
+    }
+
+    public R code(Integer code) {
+        this.setCode(code);
+        return this;
+    }
+
+    public R data(Object object) {
+        this.setData(object);
+        return this;
+    }
 
+    public R message(String message) {
+        this.setMessage(message);
+        return this;
+    }
 }

+ 0 - 4
doc/接口测试.http

@@ -1,4 +0,0 @@
-### test接口测试
-POST HTTP://127.0.0.1:10001/api/test
-Content-Type: application/json
-

+ 0 - 9
main/.gitignore

@@ -1,9 +0,0 @@
-# maven项目编译目标路径
-target/
-# vscode项目配置文件路径
-.vscode
-# office 临时文件
-~$*
-# drawio临时文件
-.$*
-*.drawio.bkp

+ 0 - 39
main/pom.xml

@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>com.nokia</groupId>
-        <artifactId>hb_springboot_parent</artifactId>
-        <version>1.0</version>
-    </parent>
-
-    <groupId>com.nokia.main</groupId>
-    <artifactId>main</artifactId>
-    <version>1.0</version>
-
-    <packaging>jar</packaging>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.nokia.common</groupId>
-            <artifactId>common</artifactId>
-            <version>1.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <scope>provided</scope>
-        </dependency>
-    </dependencies>
-
-</project>

+ 0 - 13
main/src/main/java/com/nokia/main/MainApplication.java

@@ -1,13 +0,0 @@
-package com.nokia.main;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-// scanBasePackages 指定springboot组件扫描的包
-@SpringBootApplication(scanBasePackages = { "com.nokia" })
-public class MainApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(MainApplication.class, args);
-    }
-}

+ 0 - 18
main/src/main/java/com/nokia/main/config/MvcConfig.java

@@ -1,18 +0,0 @@
-package com.nokia.main.config;
-
-import org.springframework.stereotype.Component;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-import com.nokia.common.mvc.interceptor.ControllerLogInterceptor;
-
-@Component
-public class MvcConfig implements WebMvcConfigurer {
-    @Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        // 添加拦截器
-        registry.addInterceptor(new ControllerLogInterceptor())
-                .addPathPatterns(new String[] { "/api/**" })
-                .excludePathPatterns(new String[] {});
-    }
-}

+ 0 - 13
main/src/main/java/com/nokia/main/controller/TestController.java

@@ -1,13 +0,0 @@
-package com.nokia.main.controller;
-
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class TestController {
-
-    @PostMapping("/api/test")
-    public String test() {
-        return "test ok";
-    }
-}

+ 0 - 1
main/src/main/resources/application-develop.properties

@@ -1 +0,0 @@
-server.port=10001

+ 0 - 1
main/src/main/resources/application-product.properties

@@ -1 +0,0 @@
-server.port=10001

+ 0 - 1
main/src/main/resources/application-test.properties

@@ -1 +0,0 @@
-server.port=10001

+ 0 - 5
main/src/main/resources/application.properties

@@ -1,5 +0,0 @@
-# log配置
-logging.level.com.nokia=debug
-
-# 启用的配置
-spring.profiles.active=develop

+ 0 - 9
main/src/main/resources/logback-spring.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
-    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
-    <root level="INFO">
-        <appender-ref ref="CONSOLE" />
-    </root>
-    <logger name="org.springframework.web" level="DEBUG" />
-</configuration>

+ 7 - 1
pom.xml

@@ -15,7 +15,6 @@
     <packaging>pom</packaging>
     <modules>
         <module>common</module>
-        <module>main</module>
     </modules>
 
     <properties>
@@ -28,6 +27,13 @@
 
     <dependencyManagement>
         <dependencies>
+            <!-- 项目的子模块版本开始 -->
+            <dependency>
+                <groupId>com.nokia.common</groupId>
+                <artifactId>common</artifactId>
+                <version>1.0</version>
+            </dependency>
+            <!-- 项目的子模块版本结束 -->
             <!-- https://mvnrepository.com/artifact/de.siegmar/fastcsv -->
             <dependency>
                 <groupId>de.siegmar</groupId>