陈家开发公司 1 kuukausi sitten
commit
3748cf01f8

+ 33 - 0
demo_lianxi01/.gitignore

@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/

+ 81 - 0
demo_lianxi01/pom.xml

@@ -0,0 +1,81 @@
+<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>cn.zhentao</groupId>
+    <artifactId>demo_lianxi01</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>demo_lianxi01</name>
+    <description>demo_lianxi01</description>
+    <properties>
+        <java.version>17</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>3.0.2</spring-boot.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+    </dependencies>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>17</source>
+                    <target>17</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot.version}</version>
+                <configuration>
+                    <mainClass>cn.zhentao.DemoLianxi01Application</mainClass>
+                    <skip>true</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
demo_lianxi01/src/main/java/cn/zhentao/DemoLianxi01Application.java

@@ -0,0 +1,13 @@
+package cn.zhentao;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DemoLianxi01Application {
+
+    public static void main(String[] args) {
+        SpringApplication.run(DemoLianxi01Application.class, args);
+    }
+
+}

+ 28 - 0
demo_lianxi01/src/main/java/cn/zhentao/controller/AppIdController.java

@@ -0,0 +1,28 @@
+package cn.zhentao.controller;
+
+
+import cn.zhentao.pojo.AppId;
+
+import cn.zhentao.util.Result;
+import jakarta.validation.*;
+
+
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Set;
+
+
+@RestController
+@RequestMapping("api")
+@Validated
+public class AppIdController {
+    @PostMapping("/v1/find1")
+    public Result find1(@RequestBody AppId appId,@Valid @RequestHeader("reqId") String reqId ){
+        return Result.OK("POST请求成功, reqId: " + reqId + ", appId: " + appId.getAppId());
+    }
+    @GetMapping("/v1/query")
+    public Result query(@RequestBody AppId appId,@Valid @RequestHeader("reqId") String reqId ){
+        return Result.OK("POST请求成功, reqId: " + reqId + ", appId: " + appId.getAppId());
+    }
+}

+ 67 - 0
demo_lianxi01/src/main/java/cn/zhentao/demos/web/BasicController.java

@@ -0,0 +1,67 @@
+/*
+ * Copyright 2013-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.zhentao.demos.web;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
+ */
+@Controller
+public class BasicController {
+
+    // http://127.0.0.1:8080/hello?name=lisi
+    @RequestMapping("/hello")
+    @ResponseBody
+    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
+        return "Hello " + name;
+    }
+
+    // http://127.0.0.1:8080/user
+    @RequestMapping("/user")
+    @ResponseBody
+    public User user() {
+        User user = new User();
+        user.setName("theonefx");
+        user.setAge(666);
+        return user;
+    }
+
+    // http://127.0.0.1:8080/save_user?name=newName&age=11
+    @RequestMapping("/save_user")
+    @ResponseBody
+    public String saveUser(User u) {
+        return "user will save: name=" + u.getName() + ", age=" + u.getAge();
+    }
+
+    // http://127.0.0.1:8080/html
+    @RequestMapping("/html")
+    public String html() {
+        return "index.html";
+    }
+
+    @ModelAttribute
+    public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name
+            , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) {
+        user.setName("zhangsan");
+        user.setAge(18);
+    }
+}

+ 44 - 0
demo_lianxi01/src/main/java/cn/zhentao/demos/web/PathVariableController.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.zhentao.demos.web;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
+ */
+@Controller
+public class PathVariableController {
+
+    // http://127.0.0.1:8080/user/123/roles/222
+    @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET)
+    @ResponseBody
+    public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) {
+        return "User Id : " + userId + " Role Id : " + roleId;
+    }
+
+    // http://127.0.0.1:8080/javabeat/somewords
+    @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET)
+    @ResponseBody
+    public String getRegExp(@PathVariable("regexp1") String regexp1) {
+        return "URI Part : " + regexp1;
+    }
+}

+ 43 - 0
demo_lianxi01/src/main/java/cn/zhentao/demos/web/User.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright 2013-2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.zhentao.demos.web;
+
+/**
+ * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
+ */
+public class User {
+
+    private String name;
+
+    private Integer age;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+}

+ 37 - 0
demo_lianxi01/src/main/java/cn/zhentao/pojo/AppId.java

@@ -0,0 +1,37 @@
+package cn.zhentao.pojo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import jakarta.validation.constraints.*;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class AppId {
+    @NotBlank(message = "应用id不能为空")
+    private String appId;
+    @NotBlank(message = "签名不能为空")
+    private String sign;
+    @NotNull(message = "时间戳不能为空")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long reqTime=System.currentTimeMillis();
+    @NotNull(message = "goodsId不能为空")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Integer goodsId;
+    @NotNull(message = "数量不能为空")
+    @DecimalMin(value = "1",message = "最小值1")
+    private Integer amount;
+    @NotNull(message = "价格不能为空")
+    @DecimalMin(value = "0",message = "最小值0")
+    @DecimalMax(value = "0",message = "最大值9999")
+    private BigDecimal price;
+    @NotBlank(message = "手机号不能为空")
+    @Pattern(regexp="^((13[0-9])|(14[0-9])|(15([0-9]))|(166)|(17[0-9])|(18[0-9])|(19[0-9]))\\d{11}$",message ="手机号码格式错误")
+    private String mobile;
+    @NotNull(message = "日期不能为空")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
+    private Date nowDate=new Date();
+}

+ 32 - 0
demo_lianxi01/src/main/java/cn/zhentao/util/Constant.java

@@ -0,0 +1,32 @@
+package cn.zhentao.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @ClassName: Constant
+ * @Author: 振涛教育_李小超
+ * @Date: 2024年2月26日 14:05
+ */
+public class Constant {
+
+
+    public static String TOKEN_NAME = "Authorization";
+
+    /**
+     * 请求响应码常量
+     */
+    public static final Integer RESPONSE_CODE_SUCCESS = 200;
+    public static final Integer RESPONSE_CODE_ERROR = 400;
+    public static final Integer RESPONSE_CODE_NO_LOGIN = 402;
+    public static final Integer RESPONSE_CODE_FORBIDDEN = 403;
+
+    public static final Map<Integer, String> RESPONSE_CODE_MAP = new HashMap<>();
+    static {
+        RESPONSE_CODE_MAP.put(RESPONSE_CODE_SUCCESS, "请求成功");
+        RESPONSE_CODE_MAP.put(RESPONSE_CODE_ERROR, "请求失败");
+        RESPONSE_CODE_MAP.put(RESPONSE_CODE_NO_LOGIN, "没有登录");
+        RESPONSE_CODE_MAP.put(RESPONSE_CODE_FORBIDDEN, "权限不足");
+    }
+
+}

+ 64 - 0
demo_lianxi01/src/main/java/cn/zhentao/util/Result.java

@@ -0,0 +1,64 @@
+package cn.zhentao.util;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @ClassName: Result 返回结果
+ *  code 响应码 代表请求成功/失败
+ *  message 响应信息
+ *  data 响应数据
+ * @Author: 振涛教育_李小超
+ * @Date: 2024年2月26日 13:58
+ */
+@Data
+public class Result {
+    private Integer code;//状态码
+    private String message;//提示信息
+    private Object data;//数据  集合  对象
+
+    public Result(Integer code, String message, Object data) {
+        this.code = code;
+        this.message = message;
+        this.data = data;
+    }
+
+    public Result() {
+    }
+
+    //成功响应
+    public static Result OK() {
+        return new Result(Constant.RESPONSE_CODE_SUCCESS, "操作成功", null);
+    }
+
+    public static Result OK(Object data) {
+        return new Result(Constant.RESPONSE_CODE_SUCCESS, "操作成功", data);
+    }
+
+    //失败响应
+    public static Result ERROR() {
+        return new Result(Constant.RESPONSE_CODE_ERROR, "操作失败", null);
+    }
+
+    public static Result ERROR(Object data) {
+        return new Result(Constant.RESPONSE_CODE_ERROR, "操作失败", data);
+    }
+
+    public static Result ERROR(String message) {
+        return new Result(Constant.RESPONSE_CODE_ERROR, message, null);
+    }
+
+    //未登录响应
+    public static Result NO_LOGIN(){
+        return new Result(Constant.RESPONSE_CODE_NO_LOGIN, "未登录", null);
+    }
+    public static Result NO_LOGIN(String message){
+        return new Result(Constant.RESPONSE_CODE_NO_LOGIN, message, null);
+    }
+
+    //权限不足响应
+    public static Result FORBIDDEN(){
+        return new Result(Constant.RESPONSE_CODE_FORBIDDEN, "权限不足,禁止访问", null);
+    }
+}

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

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

+ 6 - 0
demo_lianxi01/src/main/resources/static/index.html

@@ -0,0 +1,6 @@
+<html>
+<body>
+<h1>hello word!!!</h1>
+<p>this is a html page</p>
+</body>
+</html>

+ 13 - 0
demo_lianxi01/src/test/java/cn/zhentao/DemoLianxi01ApplicationTests.java

@@ -0,0 +1,13 @@
+package cn.zhentao;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class DemoLianxi01ApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}