10 changed files with 212 additions and 18 deletions
-
60src/main/java/com/example/demo/config/Mysql1DataSourceConfig.java
-
44src/main/java/com/example/demo/controller/GeneralController.java
-
4src/main/java/com/example/demo/domain/entity/User.java
-
2src/main/java/com/example/demo/domain/entity/UserGoldRecord.java
-
19src/main/java/com/example/demo/mapper/GeneralMapper.java
-
2src/main/java/com/example/demo/security/SecurityConfig.java
-
17src/main/java/com/example/demo/service/GeneralService.java
-
35src/main/java/com/example/demo/serviceImpl/GeneralServiceImpl.java
-
36src/main/resources/application.yml
-
11src/main/resources/mapper/GeneralMapper.xml
@ -0,0 +1,60 @@ |
|||||
|
package com.example.demo.config; |
||||
|
|
||||
|
import com.zaxxer.hikari.HikariDataSource; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.ibatis.session.SqlSessionFactory; |
||||
|
import org.mybatis.spring.SqlSessionFactoryBean; |
||||
|
import org.mybatis.spring.SqlSessionTemplate; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.boot.jdbc.DataSourceBuilder; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Configuration |
||||
|
public class Mysql1DataSourceConfig { |
||||
|
|
||||
|
// @Bean(name = "mysql1DataSource") |
||||
|
//// @Primary |
||||
|
// public DataSource mysql1DataSource() { |
||||
|
// HikariDataSource dataSource = new HikariDataSource(); |
||||
|
// dataSource.setJdbcUrl("jdbc:mysql://54.251.137.151:10701/hwgold?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=UTF-8"); |
||||
|
// dataSource.setUsername("hwgold"); |
||||
|
// dataSource.setPassword("AGX4Z3YMxiCG3GR2"); |
||||
|
// dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); |
||||
|
// dataSource.setMaximumPoolSize(10); |
||||
|
// dataSource.setPoolName("mysql1HikariCP"); |
||||
|
// log.info("mysql1 DataSource initialized with pool-name: {}", dataSource.getPoolName()); |
||||
|
// return dataSource; |
||||
|
// } |
||||
|
@Bean(name = "mysql1DataSource") |
||||
|
@ConfigurationProperties(prefix = "spring.datasource.mysql1") |
||||
|
public DataSource mysql2DataSource() { |
||||
|
return DataSourceBuilder.create().type(HikariDataSource.class).build(); |
||||
|
} |
||||
|
@Bean(name = "mysql1SqlSessionFactory") |
||||
|
// @Primary |
||||
|
public SqlSessionFactory mysql1SqlSessionFactory(@Qualifier("mysql1DataSource") DataSource dataSource, |
||||
|
@Qualifier("globalConfiguration1") org.apache.ibatis.session.Configuration globalConfiguration1) throws Exception { |
||||
|
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
||||
|
sessionFactory.setDataSource(dataSource); |
||||
|
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); |
||||
|
sessionFactory.setConfiguration(globalConfiguration1); |
||||
|
return sessionFactory.getObject(); |
||||
|
} |
||||
|
|
||||
|
@Bean(name = "mysql1SqlSessionTemplate") |
||||
|
// @Primary |
||||
|
public SqlSessionTemplate mysql1SqlSessionTemplate(@Qualifier("mysql1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { |
||||
|
return new SqlSessionTemplate(sqlSessionFactory); |
||||
|
} |
||||
|
@Bean |
||||
|
@ConfigurationProperties(prefix = "mybatis.configuration.mysql1") |
||||
|
public org.apache.ibatis.session.Configuration globalConfiguration1() { |
||||
|
return new org.apache.ibatis.session.Configuration(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
package com.example.demo.controller; |
||||
|
|
||||
|
import com.example.demo.domain.vo.Result; |
||||
|
import com.example.demo.service.GeneralService; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
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; |
||||
|
|
||||
|
/** |
||||
|
* @program: GOLD |
||||
|
* @ClassName GeneralController |
||||
|
* @description: |
||||
|
* @author: huangqizhen |
||||
|
* @create: 2025−06-22 10:54 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@RestController |
||||
|
@RequestMapping("/general") |
||||
|
@RequiredArgsConstructor |
||||
|
@Slf4j |
||||
|
@CrossOrigin |
||||
|
public class GeneralController { |
||||
|
|
||||
|
@Autowired |
||||
|
private GeneralService generalService; |
||||
|
@PostMapping("/market") |
||||
|
public Result getMarket() |
||||
|
{ |
||||
|
List<String> list = generalService.getMarket(); |
||||
|
return Result.success(list); |
||||
|
} |
||||
|
@PostMapping("/platform") |
||||
|
public Result getPlatform() |
||||
|
{ |
||||
|
List<String> list = generalService.getPlatform(); |
||||
|
return Result.success(list); |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.example.demo.mapper; |
||||
|
|
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @program: GOLD |
||||
|
* @ClassName GeneralMapper |
||||
|
* @description: |
||||
|
* @author: huangqizhen |
||||
|
* @create: 2025−06-22 11:02 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Mapper |
||||
|
public interface GeneralMapper { |
||||
|
List<String> getMarket(); |
||||
|
List<String> getPlatform(); |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.example.demo.service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @program: GOLD |
||||
|
* @ClassName GeneralService |
||||
|
* @description: |
||||
|
* @author: huangqizhen |
||||
|
* @create: 2025−06-22 10:55 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
|
||||
|
public interface GeneralService { |
||||
|
List<String> getMarket(); |
||||
|
List<String> getPlatform(); |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package com.example.demo.serviceImpl; |
||||
|
|
||||
|
import com.example.demo.mapper.GeneralMapper; |
||||
|
import com.example.demo.service.GeneralService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @program: GOLD |
||||
|
* @ClassName GeneralServiceImpl |
||||
|
* @description: |
||||
|
* @author: huangqizhen |
||||
|
* @create: 2025−06-22 11:01 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Service |
||||
|
public class GeneralServiceImpl implements GeneralService { |
||||
|
|
||||
|
|
||||
|
@Autowired |
||||
|
private GeneralMapper generalMapper; |
||||
|
@Override |
||||
|
public List<String> getMarket() { |
||||
|
List<String> list = generalMapper.getMarket(); |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<String> getPlatform() { |
||||
|
List<String> list = generalMapper.getPlatform(); |
||||
|
return list; |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
<?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.example.demo.mapper.GeneralMapper"> |
||||
|
|
||||
|
<select id="getMarket" resultType="java.lang.String"> |
||||
|
select DISTINCT market from user |
||||
|
</select> |
||||
|
<select id="getPlatform" resultType="java.lang.String"> |
||||
|
select DISTINCT pay_platform from user_gold_record |
||||
|
</select> |
||||
|
</mapper> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue