浏览代码

Initial commit

Lenovo 1 月之前
当前提交
6b733bb12d

+ 38 - 0
.gitignore

@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 7 - 0
.idea/encodings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+  </component>
+</project>

+ 14 - 0
.idea/misc.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 124 - 0
.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 62 - 0
pom.xml

@@ -0,0 +1,62 @@
+<?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>
+
+    <groupId>com.zhentao</groupId>
+    <artifactId>day1</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.7.18</version> <!-- 这是最后一个支持Java 8的主要版本 -->
+    </parent>
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+            <version>2.7.18</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>3.4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.30</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>2.7.18</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.16</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.7.18</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 113 - 0
src/main/java/com/zhentao/Main.java

@@ -0,0 +1,113 @@
+package com.zhentao;
+
+import org.apache.catalina.valves.JsonErrorReportValve;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import javax.swing.*;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+@SpringBootApplication
+public class Main {
+    public static void main(String[] args) {
+        SpringApplication.run(Main.class,args);
+    }
+//
+//    public static String mindow(String s,String t){
+//        if (s==null || t==null || s.length()==0 || t.length()==0){
+//            return "";
+//        }
+////        统计t中每个字符出现的次数
+//        Map<Character,Integer> targetCount=new HashMap<>();
+//        for (char c :t.toCharArray()){
+//            targetCount.put(c,targetCount.getOrDefault(c,0)+1);
+//        }
+//        int required=targetCount.size();
+////        初始化左右指针
+//        int left =0,right =0;
+////        当前窗口中满足条件的字符种类数
+//        int formed =0;
+////        记录当前窗口中出现的字符次数
+//        Map<Character,Integer> windowCounts=new HashMap<>();
+////        最小子串的长度,起始位置、终止位置
+//        int[] ans={Integer.MAX_VALUE,-1,-1};
+//
+//        while (right<s.length()){
+//            char charscter=s.charAt(right);
+//            windowCounts.put(charscter,windowCounts.getOrDefault(charscter,0)+1);
+////            如果当前字符在t中,并且出现次数等于t中改字符的出现的次数,则满足条件的字符中种类数加1
+//            if(targetCount.containsKey(charscter) && windowCounts.get(charscter).intValue()==targetCount.get(charscter).intValue()){
+//                formed++;
+//            }
+////            当满足条件的字符种类数等于t中不同字符的种类数时,尝试缩小窗口
+//            while (left<=right && formed==required){
+//                charscter =s.charAt(left);
+////                更新最小子串的长度、起始位置和结束位置
+//                if (right-left +1<ans[0]){
+//                    ans[0]=right-left+1;
+//                    ans[1]=left;
+//                    ans[2]=right;
+//                }
+////                缩小窗口
+//                windowCounts.put(charscter,windowCounts.get(charscter)-1);
+//                if (targetCount.containsKey(charscter) && windowCounts.get(charscter).intValue()<targetCount.get(charscter).intValue()){
+//                    formed--;
+//                }
+//                left++;
+//            }
+//            right++;
+//        }
+//        return ans[0]==Integer.MAX_VALUE ? "" : s.substring(ans[1],ans[2]+1);
+//    }
+//
+//    public static void main(String[] args) {
+//        String s="ADOBECODEBANC";
+//        String t="ABC";
+//        System.err.println(mindow(s,t));
+//    }
+
+//    public int[] maxSiidingWindow(int[] nums,int k){
+//        if (nums ==null || k<-0){
+//            return new int[0];
+//        }
+//        int n=nums.length;
+//        int[] result=new int[n-k+1];
+//        int resultIndex=0;
+////        使用双瑞队列来存储数组的索引
+//        Deque<Integer> deque=new LinkedList<>();
+//
+//        for (int i=0;i<n;i++){
+////            移除队列中不在当前窗口内的元素
+//            while (!deque.isEmpty() && deque.peekFirst() <i-k+1){
+//                deque.pollFirst();
+//            }
+////            移除队列中比当前元素小的元素
+//            while (!deque.isEmpty() && nums[deque.peekLast()] <nums[i]){
+//                deque.pollLast();
+//            }
+////            将当前元素的索引加入队列
+//            deque.offerLast(i);
+//
+////            当前窗口形成后,记录窗口内的最大值
+//            if (i>=k -1){
+//                result[resultIndex++] =nums[deque.peekFirst()];
+//            }
+//        }
+//        return result;
+//    }
+//
+//    public static void main(String[] args) {
+//        Main solution=new Main();
+//        int[] nums={1,3,-1,-3,5,3,6,7};
+//        int k=3;
+//        int[] result=solution.maxSiidingWindow(nums,k);
+//        for (int num: result){
+//            System.err.println(num +" ");
+//        }
+//    }
+
+
+}

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

@@ -0,0 +1,50 @@
+package com.zhentao.controller;
+
+import com.zhentao.pojo.Rest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api")
+public class ApiController {
+//    @Autowired
+//    DemoService demoService;
+//    @PostMapping("/oder1")
+//    public ResultVo add(@Validated @ReguestBody RequestDto requestDto, @RequestHeader("regld") String regld){
+//        log.infoUsONObject.toJSONString(requestDto));
+//        return demoService.add(requestDto,regld);
+//    }
+//
+//    @GetMapping("/addv2")
+//    public ResultVo addv2( RequestDto requestDto, @RequestHeader("regld") String reqld){
+//        log.infoUSONObiect.toJSONString(requestDto));
+//        return demoService.add(requestDto,regld);
+//    }
+
+    // 接口1 - POST JSON
+    @PostMapping("/v1/order")
+    public String createOrder(
+            @RequestHeader("reqId") String reqId,
+            @Validated @RequestBody Rest request) {
+
+        return "接口1调用成功: " + request.toString();
+    }
+
+    // 接口2 - GET Form参数
+    @GetMapping("/v2/order")
+    public String getOrder(
+            @RequestHeader("reqId") String reqId,
+            @Validated Rest request) {
+        return "接口2调用成功: " + request.toString();
+    }
+
+}

+ 19 - 0
src/main/java/com/zhentao/controller/GlobalExceptionHandler.java

@@ -0,0 +1,19 @@
+package com.zhentao.controller;
+
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import java.util.stream.Collectors;
+
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public ResponseEntity<String> handleValidationExceptions(MethodArgumentNotValidException ex) {
+        String errorMsg = ex.getBindingResult().getAllErrors().stream()
+                .map(error -> error.getDefaultMessage())
+                .collect(Collectors.joining(", "));
+        return ResponseEntity.badRequest().body("参数验证失败: " + errorMsg);
+    }
+}

+ 74 - 0
src/main/java/com/zhentao/pojo/Rest.java

@@ -0,0 +1,74 @@
+package com.zhentao.pojo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.*;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Time;
+import java.util.Date;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Rest implements Serializable {
+//    @NotBlank(message = "应用不能为空")
+//    private String appId;
+//    @NotBlank(message = "签名不能为空")
+//    private String sign;
+//    @NotBlank(message = "时间戳不能为空")
+//    @JsonSerialize(using = ToStringSerializer.class)
+//    private Long reqTime;
+//
+//    @JsonFormat(shape= JsonFormat.Shape.STRING)
+//    @NotBlank(message = "goodsId 不能为空")
+//    private Integer goodsId;
+//    @DecimalMin(value = "1",message = "最小值")
+//    @NotBlank(message = "数量不能为空")
+//    private Integer amoun;
+//    @NotBlank(message = "goodsId 不能为空")
+//    @DecimalMin(value = "0",message = "最小值0")
+//    @DecimalMax(value = "9999",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{8}$",message ="手机号码格式错误")
+//    private String mobile;
+//    @NotBlank(message = "nowDate 不能为空")
+//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
+//    private Date nowDate;
+@NotBlank(message = "appId不能为空")
+private String appId;
+
+    @NotBlank(message = "sign不能为空")
+    private String sign;
+
+    @NotBlank(message = "reqTime不能为空")
+    private String reqTime;
+
+    // 业务字段
+    @NotBlank(message = "goodsId不能为空")
+    private String goodsId;
+
+    @NotNull(message = "amount不能为空")
+    @Min(value = 1, message = "数量必须大于0")
+    private Integer amount;
+
+    @NotNull(message = "price不能为空")
+    @DecimalMin(value = "0.01", message = "价格必须大于0")
+    private BigDecimal price;
+
+    @NotBlank(message = "mobile不能为空")
+    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
+    private String mobile;
+
+    @NotBlank(message = "nowDate不能为空")
+    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式应为yyyy-MM-dd")
+    private String nowDate;
+}