From 1ff30087c618906b1371c657e18d5346d17c3ffe Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 31 May 2025 18:44:23 +0800 Subject: [PATCH] 123 --- demo/.gitignore | 33 ++++++++ demo/pom.xml | 91 ++++++++++++++++++++++ .../java/com/example/demo/DemoApplication.java | 14 ++++ .../example/demo/controller/QueryController.java | 37 +++++++++ .../main/java/com/example/demo/entity/ZbInfo.java | 20 +++++ .../example/demo/repository/ZbInfoRepository.java | 12 +++ demo/src/main/resources/application.properties | 20 +++++ demo/src/main/resources/templates/index.html | 30 +++++++ .../java/com/example/DemoApplicationTests.java | 13 ++++ 9 files changed, 270 insertions(+) create mode 100644 demo/.gitignore create mode 100644 demo/pom.xml create mode 100644 demo/src/main/java/com/example/demo/DemoApplication.java create mode 100644 demo/src/main/java/com/example/demo/controller/QueryController.java create mode 100644 demo/src/main/java/com/example/demo/entity/ZbInfo.java create mode 100644 demo/src/main/java/com/example/demo/repository/ZbInfoRepository.java create mode 100644 demo/src/main/resources/application.properties create mode 100644 demo/src/main/resources/templates/index.html create mode 100644 demo/src/test/java/com/example/DemoApplicationTests.java diff --git a/demo/.gitignore b/demo/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/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/ diff --git a/demo/pom.xml b/demo/pom.xml new file mode 100644 index 0000000..58cae65 --- /dev/null +++ b/demo/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + com.example + demo + 0.0.1-SNAPSHOT + demo + demo + + 1.8 + UTF-8 + UTF-8 + 2.6.13 + + + + org.springframework.boot + spring-boot-starter-web + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.microsoft.sqlserver + mssql-jdbc + 8.4.1.jre8 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.DemoApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/demo/src/main/java/com/example/demo/DemoApplication.java b/demo/src/main/java/com/example/demo/DemoApplication.java new file mode 100644 index 0000000..626785c --- /dev/null +++ b/demo/src/main/java/com/example/demo/DemoApplication.java @@ -0,0 +1,14 @@ +package com.example.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + // 启用 TLS 1.0/1.1 + System.setProperty("jdk.tls.client.protocols", "TLSv1"); + SpringApplication.run(DemoApplication.class, args); + } +} \ No newline at end of file diff --git a/demo/src/main/java/com/example/demo/controller/QueryController.java b/demo/src/main/java/com/example/demo/controller/QueryController.java new file mode 100644 index 0000000..836b44c --- /dev/null +++ b/demo/src/main/java/com/example/demo/controller/QueryController.java @@ -0,0 +1,37 @@ +package com.example.demo.controller; + +import com.example.demo.entity.ZbInfo; +import com.example.demo.repository.ZbInfoRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class QueryController { + + @Autowired + private ZbInfoRepository repository; + + @GetMapping("/") + public String index() { + return "index"; + } + + @PostMapping("/query") + public String query(@RequestParam String jwcode, Model model) { + ZbInfo zbInfo = repository.findByJwcode(jwcode) + .orElse(null); // 不存在时返回 null + + if (zbInfo != null) { + model.addAttribute("result", zbInfo); + } else { + model.addAttribute("error", "未找到匹配记录"); + } + + model.addAttribute("jwcode", jwcode); + return "index"; + } +} \ No newline at end of file diff --git a/demo/src/main/java/com/example/demo/entity/ZbInfo.java b/demo/src/main/java/com/example/demo/entity/ZbInfo.java new file mode 100644 index 0000000..ad159eb --- /dev/null +++ b/demo/src/main/java/com/example/demo/entity/ZbInfo.java @@ -0,0 +1,20 @@ +package com.example.demo.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "zzb_store_zbright") // 替换为实际表名 +public class ZbInfo { + + @Id + private String zbid; + private String jwcode; + + // Getters and Setters + public String getZbid() { return zbid; } + public void setZbid(String zbid) { this.zbid = zbid; } + public String getJwcode() { return jwcode; } + public void setJwcode(String jwcode) { this.jwcode = jwcode; } +} \ No newline at end of file diff --git a/demo/src/main/java/com/example/demo/repository/ZbInfoRepository.java b/demo/src/main/java/com/example/demo/repository/ZbInfoRepository.java new file mode 100644 index 0000000..d5cf10c --- /dev/null +++ b/demo/src/main/java/com/example/demo/repository/ZbInfoRepository.java @@ -0,0 +1,12 @@ +package com.example.demo.repository; + +import com.example.demo.entity.ZbInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface ZbInfoRepository extends JpaRepository { + Optional findByJwcode(String jwcode); +} \ No newline at end of file diff --git a/demo/src/main/resources/application.properties b/demo/src/main/resources/application.properties new file mode 100644 index 0000000..d6a4278 --- /dev/null +++ b/demo/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# ????? +spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver +spring.datasource.url=jdbc:sqlserver://52.76.43.43:1433;databaseName=hlgbms;encrypt=true;trustServerCertificate=true;sendStringParametersAsUnicode=false +spring.datasource.username=gjb_test +spring.datasource.password=qweuio!@#$1 + + +# JPA ?? +spring.jpa.database-platform=org.hibernate.dialect.SQLServer2012Dialect +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false + +# ????? +spring.datasource.hikari.minimum-idle=5 +spring.datasource.hikari.maximum-pool-size=15 +spring.datasource.hikari.idle-timeout=30000 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.max-lifetime=1800000 \ No newline at end of file diff --git a/demo/src/main/resources/templates/index.html b/demo/src/main/resources/templates/index.html new file mode 100644 index 0000000..f9c1369 --- /dev/null +++ b/demo/src/main/resources/templates/index.html @@ -0,0 +1,30 @@ + + + + + Zbid 查询 + + + +

根据 Jwcode 查询 Zbid

+ +
+ + + +
+ +
+

Jwcode:

+

Zbid:

+
+ +
+

+
+ + \ No newline at end of file diff --git a/demo/src/test/java/com/example/DemoApplicationTests.java b/demo/src/test/java/com/example/DemoApplicationTests.java new file mode 100644 index 0000000..c900efb --- /dev/null +++ b/demo/src/test/java/com/example/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.example; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +}