springboot部分技巧、问题汇总以及解决方案

6 篇文章 0 订阅
4 篇文章 0 订阅

若需频繁调用Collection.contains 方法则使用Set

// 只考虑插入,list的速度比set快
// 如果需要频繁的使用contains 判断是否存在,使用set的会快得多
List<Object> list = new ArrayList<>();
Set<Object> set = new HashSet<>();

迭代entrySet() 获取Map 的key 和value

//Map 获取key & value 可以有效的降低代码的复杂程度
HashMap<String, String> map = new HashMap<>();
for (Map.Entry<String,String> entry : map.entrySet()){
 String key = entry.getKey();
 String value = entry.getValue();
}

mybatis-plus 3.4.2分页失效的结局方案

3.4.2与3.4.1不同。如果是3,.4.1的版本需要做以下配置

@Configuration
public class MybatisPlusConfiguration {
 
    @Bean
    public PaginationInnerInterceptor paginationInterceptor() {
        return new PaginationInnerInterceptor();
    }
 
}

3.4.2做以下配置

@Configuration(proxyBeanMethods = false)
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

springboot+mybatis-plusmapper扫描不到的问题

在启动类中加入扫描包路径

@SpringBootApplication(scanBasePackages = "com.order.order02comsumer")
@MapperScan(basePackages = "com.order.order02comsumer.mapper")
public class Order02ComsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(Order02ComsumerApplication.class, args);
    }

}

springboot中拦截器无法使用redis

需要提前实例化拦截器,再使用

 @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 使用实例化的LoginIntercepter的getLoginHandlerInterceptor()方法即可
        InterceptorRegistration registration = registry.addInterceptor(getLoginHandlerInterceptor());
        registration.addPathPatterns("/**");
        registration.excludePathPatterns("/login","/login/page");
    }


    /**
     * 提前new出 防止redis失效
     * @return
     */
    @Bean
    public LoginIntercepter getLoginHandlerInterceptor(){
        return new LoginIntercepter();
    }

打包报错:redisFailed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

去除pom.xml文件中的pom即可

linux使用nohup启动和关闭

# 查看当前运行的java程序
[root@iZwz9j8inmvsbciobnx8ulZ codeGenerator]# ps -aux | grep  java
root     24391  7.1  8.7 2962604 156124 ?      Sl   12:09   0:20 java -jar code-web-0.0.1-SNAPSHOT.jar
root     24568  0.0  0.0 112812   968 pts/0    S+   12:14   0:00 grep --color=auto java
# 杀死指定id程序
kill -s 9 24391

springboot+mybatis-plus3.4.2扫描不到mapper.xml的问题

问题描述:
1、mapper接口和mepper.xml名字一致
2、mapper.xml的命名空间和mapper接口的全限定类名一致
3、配置文件中对xml进行的配置
4、target中编译了xml文件
5、xml文件存放于resources->mybatis->mapper中

以上条件都符合按道理来说是不会出现xml扫描不到的情况的,但是偏偏就出现了。所以可以进行一下更改

1、修改pom.xml文件(在build标签下加上下面配置)
ps:这里的今天文件和html需要按文件夹引入,不然会报错

<resources>
    <!--引入mapper对应的xml文件-->
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
            <include>static/**</include>
            <include>templates/**</include>
        </includes>
    </resource>
</resources>

echarts图表自适应问题

/*在setOption之后执行下面那段代码*/
let chartDom = document.getElementById('newConn');
let newConn = echarts.init(chartDom);
let option;
option = {......}
newConn.setOption(option);
window.onresize = newConn.resize;

后端返回id精度缺失

创建配置类

package com.gj.codeweb.config;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * @author 高俊
 * @create 2021-11-2021/11/5-14:28
 */
@Configuration
public class JsonConfig {

    @Bean
    @Primary
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder)
    {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        // 全局配置序列化返回 JSON 处理
        SimpleModule simpleModule = new SimpleModule();
        //JSON Long ==> String
        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
        objectMapper.registerModule(simpleModule);
        return objectMapper;
    }
}

在实体类中使用注解

@JsonSerialize(using = ToStringSerializer.class)

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.4</version>
    <scope>compile</scope>
</dependency>

jq前端设置元素距离

$("").offset({top:value,left:value)});
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值