Browse Source

Initial commit

zhentao 1 tháng trước cách đây
commit
3a8c5faacc
28 tập tin đã thay đổi với 510 bổ sung0 xóa
  1. 23 0
      .gitignore
  2. 19 0
      HELP.md
  3. 82 0
      pom.xml
  4. 15 0
      src/main/java/com/zhentao/Demo0329Application.java
  5. 32 0
      src/main/java/com/zhentao/Demo0330Application.java
  6. 27 0
      src/main/java/com/zhentao/common/Result.java
  7. 66 0
      src/main/java/com/zhentao/controller/GoodController.java
  8. 67 0
      src/main/java/com/zhentao/demos/web/BasicController.java
  9. 44 0
      src/main/java/com/zhentao/demos/web/PathVariableController.java
  10. 43 0
      src/main/java/com/zhentao/demos/web/User.java
  11. 39 0
      src/main/java/com/zhentao/pojo/Good.java
  12. 6 0
      src/main/java/com/zhentao/service/GoodService.java
  13. 4 0
      src/main/java/com/zhentao/service/impl/GoodServiceImpl.java
  14. 9 0
      src/main/resources/application.properties
  15. 6 0
      src/main/resources/static/index.html
  16. 13 0
      src/test/java/com/zhentao/Demo0329ApplicationTests.java
  17. 9 0
      target/classes/application.properties
  18. BIN
      target/classes/com/zhentao/Demo0329Application.class
  19. BIN
      target/classes/com/zhentao/Demo0330Application.class
  20. BIN
      target/classes/com/zhentao/common/Result.class
  21. BIN
      target/classes/com/zhentao/controller/GoodController.class
  22. BIN
      target/classes/com/zhentao/demos/web/BasicController.class
  23. BIN
      target/classes/com/zhentao/demos/web/PathVariableController.class
  24. BIN
      target/classes/com/zhentao/demos/web/User.class
  25. BIN
      target/classes/com/zhentao/pojo/Good.class
  26. BIN
      target/classes/com/zhentao/service/GoodService.class
  27. BIN
      target/classes/com/zhentao/service/impl/GoodServiceImpl.class
  28. 6 0
      target/classes/static/index.html

+ 23 - 0
.gitignore

@@ -0,0 +1,23 @@
+[200~target/
+*.jar
+*.war
+*.ear
+
+# IDE
+.idea/
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings/
+bin/
+
+# Logs
+*.log
+logs/
+
+# System
+.DS_Store
+EOF~
+OF

+ 19 - 0
HELP.md

@@ -0,0 +1,19 @@
+# Getting Started
+
+### Reference Documentation
+
+For further reference, please consider the following sections:
+
+* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
+* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.6.13/maven-plugin/reference/html/)
+* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.6.13/maven-plugin/reference/html/#build-image)
+* [Spring Web](https://docs.spring.io/spring-boot/docs/2.6.13/reference/htmlsingle/#web)
+
+### Guides
+
+The following guides illustrate how to use some features concretely:
+
+* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
+* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
+* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)
+

+ 82 - 0
pom.xml

@@ -0,0 +1,82 @@
+<?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>demo03-29</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>demo03-29</name>
+    <description>demo03-29</description>
+    <properties>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>2.6.13</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>1.8</source>
+                    <target>1.8</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.Demo0329Application</mainClass>
+                    <skip>true</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 15 - 0
src/main/java/com/zhentao/Demo0329Application.java

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

+ 32 - 0
src/main/java/com/zhentao/Demo0330Application.java

@@ -0,0 +1,32 @@
+package com.zhentao;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Demo0330Application {
+    public static void main(String[] args) {
+        int[] nums={13,29,30,400};
+        int k=3;
+
+        List<Integer> list=new ArrayList<>();
+
+        for (int i=0;i<=nums.length-k;i++){
+            int index=i+k;
+            for (int j=i;j<index;j++){
+                list.add(nums[j]);
+            }
+            System.err.println("list:"+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("max:"+list.get(list.size()-1));
+            list.clear();
+        }
+    }
+}

+ 27 - 0
src/main/java/com/zhentao/common/Result.java

@@ -0,0 +1,27 @@
+package com.zhentao.common;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Result implements Serializable {
+    private Integer code;
+    private String message;
+    private Object data;
+
+    public static Result OK(String message,Object data){
+        Result result=new Result();
+        result.setCode(200);
+        result.setMessage(message);
+        result.setData(data);
+        return result;
+    }
+    public static Result ERROR(String message,Object data){
+        Result result=new Result();
+        result.setCode(400);
+        result.setMessage(message);
+        result.setData(data);
+        return result;
+    }
+}

+ 66 - 0
src/main/java/com/zhentao/controller/GoodController.java

@@ -0,0 +1,66 @@
+package com.zhentao.controller;
+
+import com.sun.net.httpserver.spi.HttpServerProvider;
+import com.zhentao.common.Result;
+import com.zhentao.pojo.Good;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import java.util.Set;
+
+@RestController
+@RequestMapping("/api")
+@Slf4j
+public class GoodController {
+//    @Autowired
+
+    //接口一
+    @PostMapping("createOrder")
+    public Result createOrder(@RequestBody Good good,@RequestHeader("reqId") String reqId){
+
+        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+        Validator validator = factory.getValidator();
+        Set<ConstraintViolation<Good>> violations = validator.validate(good);
+
+        if (violations.isEmpty()) {
+            System.out.println("邮箱地址验证通过");
+
+            return Result.OK("订单创建成功",good);
+        } else {
+            for (ConstraintViolation<Good> violation : violations) {
+                System.out.println(violation.getMessage());
+                return null;
+            }
+            return null;
+        }
+
+
+    }
+
+    //接口二
+    @GetMapping("/query")
+    public Result queryOrder(Good good,@RequestHeader("reqId") String reqId){
+        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+        Validator validator = factory.getValidator();
+        Set<ConstraintViolation<Good>> violations = validator.validate(good);
+
+        if (violations.isEmpty()) {
+            System.out.println("邮箱地址验证通过");
+
+            return Result.OK("查询成功",good);
+        } else {
+            for (ConstraintViolation<Good> violation : violations) {
+                System.out.println(violation.getMessage());
+                return null;
+            }
+            return null;
+        }
+    }
+}

+ 67 - 0
src/main/java/com/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 com.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
src/main/java/com/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 com.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
src/main/java/com/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 com.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;
+    }
+}

+ 39 - 0
src/main/java/com/zhentao/pojo/Good.java

@@ -0,0 +1,39 @@
+package com.zhentao.pojo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import javax.validation.constraints.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class Good implements Serializable {
+
+        @NotBlank(message = "appId不能为空")
+        private String appId;
+
+        @NotBlank(message = "sign不能为空")
+        private String sign;
+
+//        @NotNull(message = "reqTime不能为空")
+//        private Long reqTime;
+
+        @NotBlank(message = "goodsId不能为空")
+        private String goodsId;
+
+        @Min(value = 1, message = "数量必须大于0")
+        private Integer amount;
+
+        @DecimalMin(value = "0", message = "价格必须大于0")
+        @DecimalMax(value = "9999",message = "价格必须小于9999")
+        private Double price;
+
+        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
+        private String mobile;
+
+//        @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式应为yyyy-MM-dd")
+        @NotNull(message="日期不能为空")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone ="GMT+8")
+        private String nowDate;
+    }

+ 6 - 0
src/main/java/com/zhentao/service/GoodService.java

@@ -0,0 +1,6 @@
+package com.zhentao.service;
+
+public interface GoodService {
+
+
+}

+ 4 - 0
src/main/java/com/zhentao/service/impl/GoodServiceImpl.java

@@ -0,0 +1,4 @@
+package com.zhentao.service.impl;
+
+public class GoodServiceImpl {
+}

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

@@ -0,0 +1,9 @@
+# 应用服务 WEB 访问端口
+# ?????
+server.port=8080
+# ????
+logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] [%X{reqId}] %-5level %logger{36} - %msg%n
+# ??????????
+server.error.include-message=always
+server.error.include-binding-errors=always
+

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

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

+ 9 - 0
target/classes/application.properties

@@ -0,0 +1,9 @@
+# 应用服务 WEB 访问端口
+# ?????
+server.port=8080
+# ????
+logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] [%X{reqId}] %-5level %logger{36} - %msg%n
+# ??????????
+server.error.include-message=always
+server.error.include-binding-errors=always
+

BIN
target/classes/com/zhentao/Demo0329Application.class


BIN
target/classes/com/zhentao/Demo0330Application.class


BIN
target/classes/com/zhentao/common/Result.class


BIN
target/classes/com/zhentao/controller/GoodController.class


BIN
target/classes/com/zhentao/demos/web/BasicController.class


BIN
target/classes/com/zhentao/demos/web/PathVariableController.class


BIN
target/classes/com/zhentao/demos/web/User.class


BIN
target/classes/com/zhentao/pojo/Good.class


BIN
target/classes/com/zhentao/service/GoodService.class


BIN
target/classes/com/zhentao/service/impl/GoodServiceImpl.class


+ 6 - 0
target/classes/static/index.html

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