9 changed files with 270 additions and 0 deletions
-
33demo/.gitignore
-
91demo/pom.xml
-
14demo/src/main/java/com/example/demo/DemoApplication.java
-
37demo/src/main/java/com/example/demo/controller/QueryController.java
-
20demo/src/main/java/com/example/demo/entity/ZbInfo.java
-
12demo/src/main/java/com/example/demo/repository/ZbInfoRepository.java
-
20demo/src/main/resources/application.properties
-
30demo/src/main/resources/templates/index.html
-
13demo/src/test/java/com/example/DemoApplicationTests.java
@ -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/ |
@ -0,0 +1,91 @@ |
|||||
|
<?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.example</groupId> |
||||
|
<artifactId>demo</artifactId> |
||||
|
<version>0.0.1-SNAPSHOT</version> |
||||
|
<name>demo</name> |
||||
|
<description>demo</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.mybatis.spring.boot</groupId> |
||||
|
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||
|
<version>2.2.2</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<dependency> |
||||
|
<groupId>com.microsoft.sqlserver</groupId> |
||||
|
<artifactId>mssql-jdbc</artifactId> |
||||
|
<version>8.4.1.jre8</version> |
||||
|
</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-data-jpa</artifactId> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-thymeleaf</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.example.DemoApplication</mainClass> |
||||
|
<skip>true</skip> |
||||
|
</configuration> |
||||
|
<executions> |
||||
|
<execution> |
||||
|
<id>repackage</id> |
||||
|
<goals> |
||||
|
<goal>repackage</goal> |
||||
|
</goals> |
||||
|
</execution> |
||||
|
</executions> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
</build> |
||||
|
|
||||
|
</project> |
@ -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); |
||||
|
} |
||||
|
} |
@ -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"; |
||||
|
} |
||||
|
} |
@ -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; } |
||||
|
} |
@ -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<ZbInfo, String> { |
||||
|
Optional<ZbInfo> findByJwcode(String jwcode); |
||||
|
} |
@ -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 |
@ -0,0 +1,30 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html xmlns:th="http://www.thymeleaf.org"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<title>Zbid 查询</title> |
||||
|
<style> |
||||
|
body { max-width: 600px; margin: 20px auto; padding: 20px; } |
||||
|
.result { margin-top: 20px; padding: 10px; border: 1px solid #ddd; } |
||||
|
.error { color: red; } |
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h3>根据 Jwcode 查询 Zbid</h3> |
||||
|
|
||||
|
<form method="post" action="/query"> |
||||
|
<label for="jwcode">Jwcode:</label> |
||||
|
<input type="text" id="jwcode" name="jwcode" required> |
||||
|
<button type="submit">查询</button> |
||||
|
</form> |
||||
|
|
||||
|
<div class="result" th:if="${result}"> |
||||
|
<p>Jwcode: <span th:text="${jwcode}"></span></p> |
||||
|
<p>Zbid: <span th:text="${result.zbid}"></span></p> |
||||
|
</div> |
||||
|
|
||||
|
<div class="error" th:if="${error}"> |
||||
|
<p th:text="${error}"></p> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -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() { |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue