深夜被大雨惊醒,股市低迷,但工作中小有所获

  今天南京深夜的雨是真的大,像水从盆里倒出来一样,电闪雷鸣,把我从睡梦中惊醒,小狗也被吓得走来走去,难道又是哪位大仙在渡劫吗?

  国庆节前的股市还是跟往年一样,国庆节变成了“国庆劫”,公司有人更是来了一句“每逢佳节倍失金”,我想说这是李太白现世吧,说的这般形象!

  今天在写程序方面呢还是有点收获:

  • 小程序
    1. 小程序如何等宽高布局?
      主要使用百分比屏幕宽(vw)或者百分比屏幕高(vh)
 .lesson-item{
    width: 90vw;
    min-height:90vw;
    background-color: white;
    margin-top: 30rpx;
    display: flex;
    flex-direction: column;
  }
  1. 小程序如果进行网格布局?
    一般可能使用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()]);
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. web安全及防护 XSS(cross-site scripting)跨站脚本攻击原理:恶意攻击者往Web页面...
    Marvel_Dreamer阅读 1,333评论 0 6
  • 前端常见的一些问题 1.前端性能优化手段? 1. 尽可能使用雪碧图2. 使用字体图标代替图片3. 对HTML,cs...
    十八人言阅读 1,165评论 0 1
  • 开始之前 栅格系统,做过前端的同学对这个词应该是比较熟悉,作为90后的一批的前端程序员(甚至更早,伟哥也不不是太清...
    Geeker工作坊阅读 1,878评论 0 1
  • css 盒模型 回答问题的时候要整理思路,也就是你的思考方式是怎么样的?盒模型有两种,W3C 和IE 盒子模型1、...
    廖若晨阅读 1,242评论 0 13
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,327评论 0 11