今天南京深夜的雨是真的大,像水从盆里倒出来一样,电闪雷鸣,把我从睡梦中惊醒,小狗也被吓得走来走去,难道又是哪位大仙在渡劫吗?
国庆节前的股市还是跟往年一样,国庆节变成了“国庆劫”,公司有人更是来了一句“每逢佳节倍失金”,我想说这是李太白现世吧,说的这般形象!
今天在写程序方面呢还是有点收获:
- 小程序
- 小程序如何等宽高布局?
主要使用百分比屏幕宽(vw)或者百分比屏幕高(vh)
- 小程序如何等宽高布局?
.lesson-item{
width: 90vw;
min-height:90vw;
background-color: white;
margin-top: 30rpx;
display: flex;
flex-direction: column;
}
- 小程序如果进行网格布局?
一般可能使用table tr td 什么的,但是今天学到的度量的布局让我眼前一亮,在此记录下来
.lesson-analysis{
display: grid;
margin: 20rpx;
flex-grow: 1;
grid-template-columns: 50% 50%;
grid-template-rows: 50% 50%;
background-color: whitesmoke;
}
主要通过使用grid布局,今天是涨见识了,黏上一张布局后的效果图。
- springboot
主要收获是通过alibaba的druid并且通过aop进行多数据源切换。
pom.xml 配置
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.5.4</version>
</dependency>
java 代码
package jxt.datasource;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
public class DynamicDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey(){
return DataSourceType.getDataBaseType();
}
}
package jxt.datasource;
import org.springframework.util.StringUtils;
public class DataSourceType {
public enum DataBaseType{
MYFOOTMARK("1111111"),
MYFOOTMARKSLAVE("2222222");
private final String id;
DataBaseType(String s) {
this.id = s;
}
public String getId() {
return id;
}
}
public static final ThreadLocal<DataBaseType> TYPE = new ThreadLocal<>();
public static void setDataBaseType(DataBaseType dataBaseType){
if (dataBaseType == null){
throw new NullPointerException();
}
TYPE.set(dataBaseType);
}
public static DataBaseType getDataBaseType(){
DataBaseType dataBaseType = TYPE.get() == null?DataBaseType.MYFOOTMARK:TYPE.get();
return dataBaseType;
}
public static void setDataBaseType(String id){
if(!StringUtils.hasText(id)){
TYPE.set(DataBaseType.MYFOOTMARK);
return;
}
boolean findId = false;
for(DataBaseType dataBaseType:DataBaseType.values()){
if(dataBaseType.getId().equals(id)){
findId = true;
TYPE.set(dataBaseType);
break;
}
}
if(!findId){
TYPE.set(DataBaseType.MYFOOTMARK);
}
}
public static void clearDataBaseType(){TYPE.remove();}
}
package jxt.datasource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
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.context.annotation.Primary;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.CollectionUtils;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.*;
@Slf4j
@Configuration
@MapperScan(basePackages = "jxt.mapper", sqlSessionFactoryRef = "SqlSessionFactory")
public class DataSourceConfig {
@Primary
@Bean(name = "myfootmark")
@ConfigurationProperties(prefix = "spring.datasource.myfootmark")
public DataSource myfootmark(){return DataSourceBuilder.create().build();}
@Bean(name = "myfootmarkSlave")
@ConfigurationProperties(prefix = "spring.datasource.myfootmarkslave")
public DataSource myfootmarkSlave(){return DataSourceBuilder.create().build();}
@Bean(name = "dynamicDatasource")
public DynamicDataSource DataSource(@Qualifier("myfootmark") DataSource myfootmark,
@Qualifier("myfootmarkSlave") DataSource myfootmarkSlave){
Map<Object,Object> targetDataSource = new HashMap<>();
targetDataSource.put(DataSourceType.DataBaseType.MYFOOTMARK,myfootmark);
targetDataSource.put(DataSourceType.DataBaseType.MYFOOTMARKSLAVE,myfootmarkSlave);
DynamicDataSource dynamicDataSource = new DynamicDataSource();
dynamicDataSource.setTargetDataSources(targetDataSource);
dynamicDataSource.setDefaultTargetDataSource(myfootmark);
return dynamicDataSource;
}
@Bean(name = "SqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("dynamicDatasource") DataSource dynamicDataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dynamicDataSource);
bean.setMapperLocations(resolveMapperLocations());
return bean.getObject();
}
private Resource[] resolveMapperLocations() {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<String> mapperLocations = new ArrayList<>();
mapperLocations.add("classpath*:jxt/**/*Mapper*.xml");
List<Resource> resources = new ArrayList();
if (!CollectionUtils.isEmpty(mapperLocations)) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
log.error("Get myBatis resources happended exception",e);
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
}