Config Is a user attribute configuration framework , It's based on Xbatis Realization , Can be in SpringBoot Use in application environment , For a certain configuration attribute :
- Properties can have default values
- Different users can have different attribute values
- Property values can be dynamically updated
Each configuration attribute must set the attribute value for the default user .
User attribute configuration data is stored in MySQL, The core data structure consists of three parts :
- user (uid)
- The attribute name (name)
- Property value (value)
To configure properties propertyA、propertyB, user userA、userB For example :
| uid | name | value |
|---|---|---|
| system | propertyA | valA |
| userA | propertyA | valA2 |
| system | propertyB | valB |
system For the default user .
If you get the configuration attribute name propertyA The attribute value ( No user specified , Use default user system), return valA;
If you get users userA、 Configuration property name propertyA The attribute value , return valA2;
If you get the configuration attribute name propertyB The attribute value ( No user specified , Use default user system), return valB;
If you get users userB、 Configuration property name propertyB The attribute value ( User not set userB、 Configuration property name propertyB The attribute value , Use default user system、 Configuration property name propertyB The attribute value ), return valB;
If the get configuration attribute name does not exist , return Null value ;
By modifying the MySQL User specified in 、 Configure the attribute value of the attribute name , That is, the configuration attribute value can be dynamically updated .
install
Download the source code
git clone https://github.com/njdi/durian.git
Compile source code
cd durian/
Switch to the latest version (Tag), Such as :0.4,
git checkout 0.4
Compile and install locally Maven Warehouse :
mvn clean package
Add dependency
SpringBoot Application and use Config when , Need to be in Maven pom.xml Add :
<dependency>
<groupId>io.njdi</groupId>
<artifactId>durian-xbatis</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>io.njdi</groupId>
<artifactId>durian-config</artifactId>
<version>${version}</version>
</dependency>
${version} Replace with the specific version number , Such as :0.4.
Data sheet
Create data table :
CREATE TABLE `config` (
`id` int NOT NULL AUTO_INCREMENT,
`uid` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL,
`value` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uid_name` (`uid`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
To configure
SpringBoot Application and use Config when , Need to be in application.yml Add :
spring:
datasource:
url: jdbc:mysql://mysql_dev:13306/yurun?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
username: root
password: HUPf0elbIgAKekBR
hikari:
keepaliveTime: 30000
maxLifetime: 600000
maximumPoolSize: 30
mybatis:
mapper-locations: classpath:xbatis.xml
spring.datasource.* Related properties are used to configure the database data source .
Data table name
The data table name defaults to config, If you need to use another name , Can pass application.yml Set up :
durian:
config:
table: ${tableName}
Default user name
The default user name is called system, If you need to use another name , Can pass application.yml Set up :
durian:
config:
system: ${userName}
Use
XbatisManager
The user attribute configuration needs to be obtained and set through XbatisManager Instance implementation ,SpringBoot The application can automatically inject :
@Autowired
private XbatisManager xbatisManager;
Get configuration properties
Get the specified configuration attribute name ( The default user ) Value :
configManager.get("string");
configManager.getInt("int");
configManager.getLong("long");
configManager.getFloat("float");
configManager.getDouble("double");
configManager.getBoolean("boolean");
Get the specified configuration attribute name ( The default user ) Value ( Array ):
configManager.gets("strings");
configManager.getInts("ints");
configManager.getLongs("longs");
configManager.getFloats("floats");
configManager.getDoubles("doubles");
configManager.getBooleans("booleans");
Get the specified user 、 Configure the value of the attribute name , Overloaded methods that can use the above method names , Such as :
configManager.get("user", "string")
configManager.gets("user", "strings")
Other data types are used in a similar way , I won't repeat .
Set configuration properties
Set the specified configuration property name ( The default user ) Value :
configManager.set("string", "value");
Set the specified user 、 Configure the value of the attribute name :
configManager.set("user", "string", "value");
Other data types are used in a similar way , I won't repeat .
List configuration properties
List all configuration properties for all users :
List<ConfigBo> list(int page, int pageSize);
Lists all configuration properties for the specified user :
List<ConfigBo> listByUid(String uid, int page, int pageSize);
Lists all user attributes with the specified configuration attribute name :
List<ConfigBo> listByName(String name, int page, int pageSize);
ConfigBo An instance object of represents a user configuration property .
Delete configuration properties
Delete the specified ID Configuration properties of :
void delete(int id);
Of user configuration properties ID Can pass ConfigBo obtain .
Delete the specified user 、 Configuration attribute of the configuration attribute name :
void delete(String uid, String name);
Delete all configuration attributes of the specified user :
void deletesByUid(String uid);
Delete all configuration attributes with the specified configuration attribute name :
void deletesByName(String name);
cache
Config compatible SpringBoot Caching.






![[opencvsharp] spot detection barcode decoding image operation image rotation / flip / Zoom perspective transformation image display control demo notes](/img/a7/5b66ef0360ed41441653a413cd9e53.png)


