| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # CLAUDE.md |
| | | |
| | | This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| | | |
| | | ## Project Overview |
| | | |
| | | This is a Spring Boot 3.1.5 application with Java 17 that provides a dynamic menu system with tree structure. The application uses Microsoft SQL Server 2019 database with MyBatis Plus for data access and serves REST APIs for menu management. |
| | | |
| | | ## Key Technologies and Dependencies |
| | | |
| | | - **Spring Boot 3.1.5** with Java 17 |
| | | - **Microsoft SQL Server 2019** with MSSQL-JDBC driver |
| | | - **MyBatis Plus** for ORM and database operations |
| | | - **Alibaba Druid** for connection pooling |
| | | - **Lombok** for reducing boilerplate code |
| | | - **Alibaba FastJSON** for JSON serialization |
| | | - **Hutool** utility library |
| | | |
| | | ## Development Commands |
| | | |
| | | ### Build and Package |
| | | ```bash |
| | | mvn clean package |
| | | ``` |
| | | |
| | | ### Run Application |
| | | ```bash |
| | | mvn spring-boot:run |
| | | ``` |
| | | |
| | | ### Run Tests |
| | | ```bash |
| | | mvn test |
| | | ``` |
| | | |
| | | ### Generate JAR with dependencies |
| | | ```bash |
| | | mvn clean package -DskipTests |
| | | ``` |
| | | |
| | | ### Run Production JAR |
| | | Use the provided startup script: |
| | | ```bash |
| | | # Windows |
| | | src/main/startup.bat |
| | | |
| | | # Or manually with custom SQL Server connection: |
| | | java -jar -Dspring.datasource.url="jdbc:sqlserver://HOST:PORT;databaseName=DATABASE;encrypt=true;trustServerCertificate=true" -Dspring.datasource.username=USERNAME -Dspring.datasource.password=PASSWORD simple.jar |
| | | ``` |
| | | |
| | | **Note**: Both `encrypt=true` and `encrypt=false` work with `trustServerCertificate=true`. The startup.bat uses `encrypt=true`. |
| | | |
| | | ## Application Architecture |
| | | |
| | | ### Package Structure |
| | | - `com.gs.simple` - Root package |
| | | - `common/` - Shared utilities (DatabaseConfig, ResultDto) |
| | | - `controller/` - REST controllers |
| | | - `domain/` - Entity classes (MesSimplesimple, TreeView, Children) |
| | | - `mapper/` - MyBatis mappers for database access |
| | | - `service/` - Business logic layer with implementation |
| | | |
| | | ### Key Components |
| | | |
| | | **SimpleController** (`controller/SimpleController.java:16-35`) |
| | | - Main REST controller with CORS enabled |
| | | - Endpoints: `/simple/getTree` (POST) and `/simple/list` (POST) |
| | | |
| | | **MesSimpleService** (`service/MesSimpleService.java:15-23`) |
| | | - Core business logic for menu operations |
| | | - Methods: `getTree()`, `toTree()`, `getMenuList()` |
| | | |
| | | **TreeView Domain** (`domain/TreeView.java:13-24`) |
| | | - Represents hierarchical menu structure with id, title, field, spread, and children |
| | | |
| | | ### Database Configuration |
| | | - **Default**: SQL Server database at 192.168.0.51:1433 (database: TEST_MES) |
| | | - **Schema Initialization**: Use `MES_SIMPLE_CREATE_TABLE.sql` to create the required database table |
| | | - **Runtime Override**: Use system properties or startup.bat for different environments without rebuilding |
| | | - **Connection Pool**: Druid with 5-20 connections, 60s timeout |
| | | - **MyBatis**: XML mappers in `src/main/resources/mapper/` |
| | | |
| | | ## Development Notes |
| | | |
| | | - Server runs on port **9091** by default |
| | | - Spring Boot Actuator endpoints available for monitoring |
| | | - MyBatis Plus uses AUTO ID generation strategy |
| | | - SQL logging enabled via StdOutImpl for debugging |
| | | - Camel case mapping enabled for SQL Server database columns |
| | | - JDBC null handling configured for SQL Server compatibility (`jdbc-type-for-null: 'null'`) |
| | | - Application supports runtime database configuration override via JVM properties |
| | | - Druid SQL wall filter enabled for SQL injection protection with multi-statement support |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | -- SQL Serverå»ºè¡¨èæ¬ - èåç»´æ¤è¡¨ |
| | | -- 对åºJavaå®ä½ç±»: com.gs.simple.domain.MesSimplesimple |
| | | |
| | | -- å¦æè¡¨å·²åå¨åå é¤ |
| | | IF OBJECT_ID('dbo.MES_SIMPLE', 'U') IS NOT NULL |
| | | DROP TABLE dbo.MES_SIMPLE; |
| | | |
| | | -- å建èåç»´æ¤è¡¨ |
| | | CREATE TABLE dbo.MES_SIMPLE ( |
| | | -- èªå¢åï¼ä½¿ç¨IDENTITYæ¿ä»£Oracleåºå |
| | | id BIGINT IDENTITY(1,1) PRIMARY KEY, |
| | | |
| | | -- æ¯å¦ä¸ºæ ¹èç¹ (0è¡¨ç¤ºä¸ºæ ¹èç¹) |
| | | is_top INT NULL, |
| | | |
| | | -- ç¶èç¹id |
| | | fid BIGINT NULL, |
| | | |
| | | -- åç§° |
| | | title NVARCHAR(255) NULL, |
| | | |
| | | -- è±æå |
| | | field NVARCHAR(255) NULL, |
| | | |
| | | -- å°å |
| | | href NVARCHAR(500) NULL, |
| | | |
| | | -- èç¹æ¯å¦åå§å±å¼ (0为ä¸å±å¼ï¼1为å±å¼) |
| | | spread INT NULL, |
| | | |
| | | -- èç¹æ¯å¦ä¸ºå±ç¤º (0为å±ç¤ºï¼1为ä¸å±ç¤º) |
| | | disabled INT NULL |
| | | ); |
| | | |
| | | -- æ·»å 表注éï¼SQL Serverä½¿ç¨æ©å±å±æ§ï¼ |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'èåç»´æ¤è¡¨', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE'; |
| | | |
| | | -- æ·»å åæ³¨é |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'èªå¢å主é®', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'id'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'æ¯å¦ä¸ºæ ¹èç¹(0è¡¨ç¤ºä¸ºæ ¹èç¹)', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'is_top'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'ç¶èç¹id', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'fid'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'åç§°', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'title'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'è±æå', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'field'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'å°å', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'href'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'èç¹æ¯å¦åå§å±å¼(0为ä¸å±å¼ï¼1为å±å¼)', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'spread'; |
| | | |
| | | EXEC sys.sp_addextendedproperty |
| | | @name=N'MS_Description', |
| | | @value=N'èç¹æ¯å¦ä¸ºå±ç¤º(0为å±ç¤ºï¼1为ä¸å±ç¤º)', |
| | | @level0type=N'SCHEMA', |
| | | @level0name=N'dbo', |
| | | @level1type=N'TABLE', |
| | | @level1name=N'MES_SIMPLE', |
| | | @level2type=N'COLUMN', |
| | | @level2name=N'disabled'; |
| | | |
| | | -- å建å¤é®çº¦æï¼èªå
³èï¼ |
| | | ALTER TABLE dbo.MES_SIMPLE |
| | | ADD CONSTRAINT FK_MES_SIMPLE_FID |
| | | FOREIGN KEY (fid) REFERENCES dbo.MES_SIMPLE(id); |
| | | |
| | | -- åå»ºç´¢å¼æé«æ¥è¯¢æ§è½ |
| | | CREATE INDEX IX_MES_SIMPLE_FID ON dbo.MES_SIMPLE(fid); |
| | | CREATE INDEX IX_MES_SIMPLE_IS_TOP ON dbo.MES_SIMPLE(is_top); |
| | | CREATE INDEX IX_MES_SIMPLE_DISABLED ON dbo.MES_SIMPLE(disabled); |
| | | |
| | | -- æå
¥ç¤ºä¾æ°æ® |
| | | INSERT INTO dbo.MES_SIMPLE (is_top, fid, title, field, href, spread, disabled) VALUES |
| | | (0, NULL, 'ç³»ç»ç®¡ç', 'system', '#', 1, 0), |
| | | (1, 1, 'èå管ç', 'menu', '/menu/list', 0, 0), |
| | | (1, 1, 'ç¨æ·ç®¡ç', 'user', '/user/list', 0, 0), |
| | | (0, NULL, 'æ°æ®ç®¡ç', 'data', '#', 0, 0), |
| | | (1, 4, 'æ°æ®å¯¼å
¥', 'import', '/data/import', 0, 0), |
| | | (1, 4, 'æ°æ®å¯¼åº', 'export', '/data/export', 0, 0); |
| | | |
| | | -- æ¥çåå»ºç»æ |
| | | SELECT |
| | | id, |
| | | is_top, |
| | | fid, |
| | | title, |
| | | field, |
| | | href, |
| | | spread, |
| | | disabled |
| | | FROM dbo.MES_SIMPLE |
| | | ORDER BY id; |
| | |
| | | ## LBKBSql_Service |
| | | |
| | | è½®æçæ¿åå° |
| | | # gs-simple |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" |
| | | 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> |
| | | <parent> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-parent</artifactId> |
| | | <version>3.1.5</version> |
| | | <relativePath/> <!-- lookup parent from repository --> |
| | | </parent> |
| | | <groupId>com.gs</groupId> |
| | | <artifactId>simple</artifactId> |
| | | <version>1.0.2-SNAPSHOT</version> |
| | | <name>simple</name> |
| | | <description>simple</description> |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.microsoft.sqlserver</groupId> |
| | | <artifactId>mssql-jdbc</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>com.alibaba</groupId> |
| | | <artifactId>druid-spring-boot-starter</artifactId> |
| | | <version>1.2.16</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>fastjson</artifactId> |
| | | <version>2.0.48</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> |
| | | <version>3.5.6</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>cn.hutool</groupId> |
| | | <artifactId>hutool-all</artifactId> |
| | | <version>5.8.22</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>simple</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-maven-plugin</artifactId> |
| | | <configuration> |
| | | <excludes> |
| | | <exclude> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </exclude> |
| | | </excludes> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | <repositories> |
| | | <repository> |
| | | <id>maven_central</id> |
| | | <name>Maven Central</name> |
| | | <url>https://repo.maven.apache.org/maven2/</url> |
| | | </repository> |
| | | </repositories> |
| | | |
| | | </project> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple; |
| | | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | |
| | | @SpringBootApplication |
| | | @MapperScan(value = "com.gs.simple.mapper") |
| | | public class SimpleApplication { |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(SimpleApplication.class, args); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.common; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.core.env.ConfigurableEnvironment; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.core.env.MapPropertySource; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | @RequiredArgsConstructor |
| | | public class DatabaseConfig { |
| | | |
| | | private final Environment env; |
| | | |
| | | public void updateDatabaseConfig(String newUrl, String newUsername, String newPassword) { |
| | | // 使ç¨Environment对象æ¥å¨æä¿®æ¹å±æ§ |
| | | ((ConfigurableEnvironment) env).getPropertySources().addFirst(new MapPropertySource("dynamicProperties", Map.of("spring.datasource.url", newUrl, "spring.datasource.username", newUsername, "spring.datasource.password", newPassword))); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.common; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | public class ResultDto<T> implements Serializable { |
| | | |
| | | private int code; |
| | | |
| | | private String msg; |
| | | |
| | | private T data; |
| | | |
| | | private int count; |
| | | |
| | | public ResultDto() { |
| | | } |
| | | |
| | | public ResultDto(int code, String msg, T data, int count) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | this.data = data; |
| | | this.count = count; |
| | | } |
| | | |
| | | public ResultDto(int code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public static <T> ResultDto<T> ok(T data, int count) { |
| | | return new ResultDto<>(0, "è¯·æ±æå", data, count); |
| | | } |
| | | |
| | | public static <T> ResultDto<T> error(String message) { |
| | | return new ResultDto<>(500, message, null, 0); |
| | | } |
| | | |
| | | public int getCount() { |
| | | return count; |
| | | } |
| | | |
| | | public void setCount(int count) { |
| | | this.count = count; |
| | | } |
| | | |
| | | public int getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(int code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) { |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public T getData() { |
| | | return data; |
| | | } |
| | | |
| | | public void setData(T data) { |
| | | this.data = data; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.controller; |
| | | |
| | | |
| | | import com.gs.simple.common.ResultDto; |
| | | import com.gs.simple.domain.MesSimplesimple; |
| | | import com.gs.simple.domain.TreeView; |
| | | import com.gs.simple.service.MesSimpleService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @RequestMapping("simple") |
| | | @RequiredArgsConstructor |
| | | @CrossOrigin(origins = "*") //è·¨åè¯·æ± |
| | | public class SimpleController { |
| | | |
| | | private final MesSimpleService simpleService; |
| | | |
| | | |
| | | @PostMapping("/getTree") |
| | | public ResultDto<List<TreeView>> getTree() { |
| | | return simpleService.getTree(); |
| | | } |
| | | |
| | | |
| | | @PostMapping("list") |
| | | public ResultDto<List<MesSimplesimple>> getList() { |
| | | return simpleService.getMenuList(); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | @Data |
| | | @TableName(value = "MES_SIMPLE_CCB") |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class BiView implements Serializable { |
| | | private Integer id; |
| | | private Integer pid; |
| | | private String name; |
| | | private String href; |
| | | private Integer lbtime; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.domain; |
| | | |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class Children { |
| | | |
| | | private Long id; |
| | | |
| | | private String title; |
| | | |
| | | private String field; |
| | | |
| | | private String href; |
| | | |
| | | //private List<Children> children; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.io.Serial; |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * èåç»´æ¤è¡¨ |
| | | * |
| | | * @TableName MES_SIMPLE |
| | | */ |
| | | @TableName(value = "MES_SIMPLE") |
| | | @Data |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesSimplesimple implements Serializable { |
| | | @Serial |
| | | @TableField(exist = false) |
| | | private static final long serialVersionUID = 1L; |
| | | /** |
| | | * èªå¢åï¼ä½¿ç¨SQL Server IDENTITYå |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * æ¯å¦ä¸ºæ ¹èç¹ 0è¡¨ç¤ºä¸ºæ ¹èç¹ |
| | | */ |
| | | private Integer isTop; |
| | | /** |
| | | * ç¶èç¹id |
| | | */ |
| | | private Long fid; |
| | | /** |
| | | * åç§° |
| | | */ |
| | | private String title; |
| | | /** |
| | | * è±æå |
| | | */ |
| | | private String field; |
| | | /** |
| | | * å°å |
| | | */ |
| | | private String href; |
| | | /** |
| | | * èç¹æ¯å¦åå§å±å¼ 0为ä¸å±å¼ï¼1为å±å¼ |
| | | */ |
| | | private Integer spread; |
| | | /** |
| | | * èç¹æ¯å¦ä¸ºå±ç¤º 0为å±ç¤ºï¼1为ä¸å±ç¤º |
| | | */ |
| | | private Integer disabled; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.domain; |
| | | |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class TreeView { |
| | | |
| | | private Long id; |
| | | |
| | | private String title; |
| | | |
| | | private String field; |
| | | |
| | | private Boolean spread; |
| | | |
| | | private List<Children> children; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.gs.simple.domain.MesSimplesimple; |
| | | |
| | | /** |
| | | * @author 28567 |
| | | * @description é对表ãMES_SIMPLE(èåç»´æ¤è¡¨)ãçæ°æ®åºæä½Mapper |
| | | * @createDate 2023-11-08 14:19:52 |
| | | * @Entity com.gs.simple.domain.MesSimplesimple |
| | | */ |
| | | public interface MesSimpleMapper extends BaseMapper<MesSimplesimple> { |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.gs.simple.common.ResultDto; |
| | | import com.gs.simple.domain.MesSimplesimple; |
| | | import com.gs.simple.domain.TreeView; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author 28567 |
| | | * @description é对表ãMES_SIMPLE(èåç»´æ¤è¡¨)ãçæ°æ®åºæä½Service |
| | | * @createDate 2023-11-08 14:19:52 |
| | | */ |
| | | public interface MesSimpleService extends IService<MesSimplesimple> { |
| | | |
| | | |
| | | ResultDto<List<TreeView>> getTree(); |
| | | |
| | | List<TreeView> toTree(); |
| | | |
| | | ResultDto<List<MesSimplesimple>> getMenuList(); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gs.simple.common.ResultDto; |
| | | import com.gs.simple.domain.Children; |
| | | import com.gs.simple.domain.MesSimplesimple; |
| | | import com.gs.simple.domain.TreeView; |
| | | import com.gs.simple.mapper.MesSimpleMapper; |
| | | import com.gs.simple.service.MesSimpleService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author 28567 |
| | | * @description é对表ãMES_SIMPLE(èåç»´æ¤è¡¨)ãçæ°æ®åºæä½Serviceå®ç° |
| | | * @createDate 2023-11-08 14:19:52 |
| | | */ |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequiredArgsConstructor |
| | | public class MesSimpleServiceImpl extends ServiceImpl<MesSimpleMapper, MesSimplesimple> implements MesSimpleService { |
| | | |
| | | |
| | | // å建ä¸ä¸ªå
å«10个线ç¨ççº¿ç¨æ± ï¼ç¨äºæ°æ®åºæä½ |
| | | private final Executor dbExecutor = Executors.newFixedThreadPool(10); |
| | | |
| | | @Override |
| | | public ResultDto<List<TreeView>> getTree() { |
| | | List<TreeView> tree = toTree(); |
| | | return ResultDto.ok(tree, tree.size()); |
| | | } |
| | | |
| | | @Override |
| | | public List<TreeView> toTree() { |
| | | return convertToTreeViewList(getTopList()); |
| | | } |
| | | |
| | | @Override |
| | | public ResultDto<List<MesSimplesimple>> getMenuList() { |
| | | LambdaQueryWrapper<MesSimplesimple> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(MesSimplesimple::getDisabled, 0).gt(MesSimplesimple::getIsTop, 0); |
| | | List<MesSimplesimple> list = list(wrapper); |
| | | return ResultDto.ok(list, list.size()); |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * è·åæ ¹èç¹ |
| | | * </p> |
| | | * |
| | | * @return java.util.List<com.gs.simple.domain.MesSimplesimple> |
| | | * @author tjx |
| | | * @date 2023/11/8 14:39 |
| | | */ |
| | | private List<MesSimplesimple> getTopList() { |
| | | LambdaQueryWrapper<MesSimplesimple> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(MesSimplesimple::getIsTop, 0).eq(MesSimplesimple::getDisabled, 0); |
| | | return list(queryWrapper); |
| | | } |
| | | |
| | | // å°MesSimplesimpleå表转æ¢ä¸ºTreeViewå表 |
| | | private List<TreeView> convertToTreeViewList(List<MesSimplesimple> mesSimplesimpleList) { |
| | | // 使ç¨CompletableFuture弿¥å¤çæ¯ä¸ªMesSimplesimple对象ï¼å¹¶æ¶é为ä¸ä¸ªCompletableFutureå表 |
| | | List<CompletableFuture<TreeView>> treeViewFutures = mesSimplesimpleList.stream().map(mesSimplesimple -> convertToTreeViewAsync(mesSimplesimple, dbExecutor)).toList(); |
| | | |
| | | // å建ä¸ä¸ªCompletableFutureï¼çå¾
ææå¼æ¥ä»»å¡å®æ |
| | | CompletableFuture<Void> allFutures = CompletableFuture.allOf(treeViewFutures.toArray(new CompletableFuture[0])); |
| | | |
| | | // 卿æå¼æ¥ä»»å¡å®æåï¼å°ç»ææ¶é为ä¸ä¸ªTreeViewå表 |
| | | return allFutures.thenApply(v -> treeViewFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())).join(); |
| | | } |
| | | |
| | | // å°MesSimplesimple对象转æ¢ä¸ºTreeView对象ï¼å¹¶ä½¿ç¨èªå®ä¹çº¿ç¨æ± æ§è¡å¼æ¥ä»»å¡ |
| | | private CompletableFuture<TreeView> convertToTreeViewAsync(MesSimplesimple mesSimplesimple, Executor executor) { |
| | | return CompletableFuture.supplyAsync(() -> convertToTreeView(mesSimplesimple), executor); |
| | | } |
| | | |
| | | private TreeView convertToTreeView(MesSimplesimple mesSimplesimple) { |
| | | TreeView treeView = new TreeView(); |
| | | treeView.setId(mesSimplesimple.getId()); |
| | | treeView.setTitle(mesSimplesimple.getTitle()); |
| | | treeView.setField(mesSimplesimple.getField()); |
| | | treeView.setSpread(mesSimplesimple.getSpread() == 1); |
| | | |
| | | //æç´¢åèç¹ |
| | | LambdaQueryWrapper<MesSimplesimple> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(MesSimplesimple::getDisabled, 0).eq(MesSimplesimple::getFid, mesSimplesimple.getId()); |
| | | List<MesSimplesimple> list = list(wrapper); |
| | | |
| | | List<Children> childrenList = new ArrayList<>(); |
| | | list.forEach(s -> { |
| | | Children children = new Children(); |
| | | children.setId(s.getId()); |
| | | children.setTitle(s.getTitle()); |
| | | children.setField(s.getField()); |
| | | children.setHref(s.getHref()); |
| | | childrenList.add(children); |
| | | }); |
| | | treeView.setChildren(childrenList); |
| | | |
| | | return treeView; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | server: |
| | | port: 9091 |
| | | |
| | | spring: |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | #龿¥éææ´æ¢ï¼ç®å使ç¨çæ¯SQL Serveræ°æ®åº |
| | | url: jdbc:sqlserver://192.168.0.51:1433;databaseName=TEST_MES;encrypt=true;trustServerCertificate=true |
| | | username: sa |
| | | password: LanBao@2025 |
| | | druid: |
| | | # é
ç½®åå§å大å°ãæå°ãæå¤§çº¿ç¨æ° |
| | | initialSize: 5 |
| | | minIdle: 5 |
| | | # CPUæ ¸æ°+1ï¼ä¹å¯ä»¥å¤§äºä½ä¸è¦è¶
è¿20ï¼æ°æ®åºå éæ¶è¿æ¥è¿å¤æ§è½ä¸é |
| | | maxActive: 20 |
| | | # æå¤§çå¾
æ¶é´ï¼å
ç½ï¼800ï¼å¤ç½ï¼1200ï¼ä¸æ¬¡æ¡æ1sï¼ |
| | | maxWait: 60000 |
| | | timeBetweenEvictionRunsMillis: 60000 |
| | | # é
ç½®ä¸ä¸ªè¿æ¥å¨æ± ä¸æå¤§ç©ºé´æ¶é´ï¼å使¯æ¯«ç§ |
| | | minEvictableIdleTimeMillis: 300000 |
| | | validationQuery: SELECT 1 |
| | | # ææè¿æ¥æ¯å¦è¢«ç©ºé²è¿æ¥åæ¶å¨(妿æ)è¿è¡æ£éª.å¦ææ£æµå¤±è´¥,åè¿æ¥å°è¢«ä»æ± ä¸å»é¤. |
| | | test-while-idle: true |
| | | # 建议é
置为falseãè·åè¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼è¿ä¸ªé
ç½®ä¼é使§è½ã |
| | | test-on-borrow: false |
| | | # 建议é
置为falseãè·åè¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼è¿ä¸ªé
ç½®ä¼é使§è½ã |
| | | test-on-return: false |
| | | # å¯ä»¥æ¯æPSCacheï¼æååå
¥ãæ¥è¯¢æçï¼ |
| | | poolPreparedStatements: true |
| | | # é
ç½®çæ§ç»è®¡æ¦æªçfiltersï¼å»æåçæ§çé¢sqlæ æ³ç»è®¡ï¼'wall'ç¨äºé²ç«å¢ |
| | | filters: stat,wall,log4j |
| | | # ä¿æé¿è¿æ¥ |
| | | keepAlive: true |
| | | maxPoolPreparedStatementPerConnectionSize: 20 |
| | | useGlobalDataSourceStat: true |
| | | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 |
| | | # é²å¾¡SQL注å
¥ |
| | | filter: |
| | | wall: |
| | | config: |
| | | multi-statement-allow: true |
| | | |
| | | custom: |
| | | datasource: |
| | | url: '@custom.datasource.url@' |
| | | username: '@custom.datasource.username@' |
| | | password: '@custom.datasource.password@' |
| | | |
| | | # mybatis-plusç¸å
³é
ç½® |
| | | mybatis-plus: |
| | | global-config: |
| | | db-config: |
| | | # 主é®ç±»å AUTO:"æ°æ®åºIDèªå¢" |
| | | # INPUT:"ç¨æ·è¾å
¥ID", |
| | | # ID_WORKER:"å
¨å±å¯ä¸ID (æ°åç±»åå¯ä¸ID)", |
| | | # UUID:"å
¨å±å¯ä¸ID UUID"; |
| | | id-type: AUTO |
| | | configuration: |
| | | #å¼å¯sqlæ¥å¿ |
| | | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
| | | # æ¯å¦å¼å¯èªå¨é©¼å³°å½åè§åæ å°:仿°æ®åºååå°Java屿§é©¼å³°å½åç类似æ å° |
| | | map-underscore-to-camel-case: true |
| | | # è§£å³SQL Serveræ´æ°æ°æ®ä¸ºnullæ¶æ æ³è½¬æ¢æ¥é |
| | | jdbc-type-for-null: 'null' |
| | | #å®ä½ç±»æå¨å
|
| | | type-aliases-package: com.gs.simple.domain.* |
| | | # xmlæ«æï¼å¤ä¸ªç®å½ç¨éå·æè
åå·åéï¼åè¯ Mapper æå¯¹åºç XML æä»¶ä½ç½®ï¼ |
| | | mapper-locations: classpath:mapper/*.xml |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.gs.simple.mapper.MesSimpleMapper"> |
| | | |
| | | </mapper> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | @echo off |
| | | set JAVA_HOME=C:\Program Files\Java\jdk-17 |
| | | set PATH=%JAVA_HOME%\bin;%PATH% |
| | | |
| | | |
| | | java -jar -Dspring.datasource.url="jdbc:sqlserver://192.168.0.51:1433;databaseName=TEST_MES;encrypt=true;trustServerCertificate=true" -Dspring.datasource.username=sa -Dspring.datasource.password="LanBao@2025" simple.jar |
| | | |
| | | pause |
| | | |
| | | attrib +r %0 |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.gs.simple; |
| | | |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | @SpringBootTest |
| | | class SimpleApplicationTests { |
| | | |
| | | @Test |
| | | void contextLoads() { |
| | | } |
| | | |
| | | } |