zhentao hai 1 mes
achega
b5455bc412

+ 33 - 0
demo/.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/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>com.zhentao</groupId>
+    <artifactId>demo</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>demo</name>
+    <description>demo</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>com.zhentao.DemoApplication</mainClass>
+                    <skip>true</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
demo/src/main/java/com/zhentao/DemoApplication.java

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

+ 31 - 0
demo/src/main/java/com/zhentao/Path.java

@@ -0,0 +1,31 @@
+package com.zhentao;
+
+import org.springframework.boot.SpringApplication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Path {
+    public static void main(String[] args) {
+        int[] nums = {90,65,101,25,79,82,91,78};
+        int k = 4;
+        //0 1 2 3 4 5 6 7     8-3
+        for(int i = 0; i <= nums.length-k; i++){
+            int index=i+k;
+            List<Integer> list = new ArrayList<>();
+            for(int j = i; j < index; j++){
+                list.add(nums[j]);
+            }
+            System.err.println(list);
+            for(int j = 0; j < list.size()-1; j++){
+                int max = list.get(j);
+                if(max > list.get(j+1)){
+                    list.set(j,list.get(j+1));
+                    list.set(j+1,max);
+                }
+            }
+            System.err.println(list.get(list.size()-1));
+            list.clear();
+        }
+    }
+}

+ 40 - 0
demo/src/main/java/com/zhentao/Path2.java

@@ -0,0 +1,40 @@
+package com.zhentao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Path2 {
+    public static void main(String[] args) {
+        String str = "abcdfasgfersfsabsdfc";
+        char[] chars = str.toCharArray();
+        String str2 = "abc";
+        char[] chars2 = str2.toCharArray();
+        Boolean aBoolean = false;
+        Boolean[] booleans = new Boolean[chars2.length];
+        booleans[0] = false;
+        booleans[1] = false;
+        booleans[2] = false;
+        List<String> list=new ArrayList<>();
+            for (int i = 0; i < chars.length; i++) {
+                for (int j = 0; j < chars2.length;) {
+                    if (chars[i] == chars2[j]) {
+                        booleans[j] = true;
+                        if (booleans[booleans.length-1] == true) {
+                            aBoolean=true;
+                            return;
+                        }
+                       else {
+                            if (booleans[j] == true) {
+                                j++;
+                            }
+                        }
+                    }
+                    String s = String.valueOf(chars[i]);
+                    if (booleans[0] == true) {
+                        list.add(s);
+                    }
+                }
+            }
+        System.err.println(list);
+    }
+}

+ 64 - 0
demo/src/main/java/com/zhentao/controller/ApiController.java

@@ -0,0 +1,64 @@
+package com.zhentao.controller;
+
+import com.zhentao.pojo.Object1;
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.Validation;
+import jakarta.validation.Validator;
+import jakarta.validation.ValidatorFactory;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.Set;
+
+@RestController
+@RequestMapping("api")
+public class ApiController {
+    @RequestMapping("/find1")
+    public Object1 find1(@RequestBody Object1 object1,@RequestHeader("reqId") String reqId){
+
+        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+        Validator validator = factory.getValidator();
+        Set<ConstraintViolation<Object1>> violations = validator.validate(object1);
+
+        if (violations.isEmpty()) {
+            System.out.println("邮箱地址验证通过");
+
+            return object1;
+        } else {
+            for (ConstraintViolation<Object1> violation : violations) {
+                System.out.println(violation.getMessage());
+                return null;
+            }
+            return null;
+        }
+    }
+    @RequestMapping("/find2")
+    public Object1 find2(String appId,
+                                Integer goodsId,
+                         BigDecimal price,
+                         String mobile,@RequestHeader("reqId") String reqId){
+        Object1 object1=new Object1();
+        object1.setAppId(appId);
+        object1.setGoodsId(goodsId);
+        object1.setPrice(price);
+        object1.setMobile(mobile);
+        System.err.println(reqId);
+        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+        Validator validator = factory.getValidator();
+        Set<ConstraintViolation<Object1>> violations = validator.validate(object1);
+        if (violations.isEmpty()) {
+            System.out.println("邮箱地址验证通过");
+
+            return object1;
+        } else {
+            for (ConstraintViolation<Object1> violation : violations) {
+                System.out.println(violation.getMessage());
+                return null;
+            }
+            return null;
+        }
+    }
+}

+ 26 - 0
demo/src/main/java/com/zhentao/pojo/Object1.java

@@ -0,0 +1,26 @@
+package com.zhentao.pojo;
+
+import jakarta.validation.constraints.*;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Date;
+
+@Data
+public class Object1 {
+    @NotNull
+    private String appId;
+    private long createTime=System.currentTimeMillis();
+    @NotNull
+    private Integer goodsId;
+    @NotNull
+    @DecimalMin(value = "0",message = "最小是0")
+    @DecimalMax(value = "9999",message = "最大是9999")
+    private BigDecimal price;
+    @NotNull
+    @Pattern(regexp = "^\\d{11}$", message = "手机号必须是 11 位数字")
+    private String mobile;
+    @NotNull
+    private Date nowDate=new Date();
+}

+ 3 - 0
demo/src/main/resources/application.properties

@@ -0,0 +1,3 @@
+# 应用服务 WEB 访问端口
+server.port=8080
+

+ 6 - 0
demo/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/src/test/java/com/zhentao/DemoApplicationTests.java

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