springboot2部分细节(持续更新)

1.防止表单重复提交数据:重定向网址 

 2.

抽取公共页面时的几种方式 

 抽取后结果如下所示

3.若所需版本与springboot2默认的仲裁版本不一致,比如我的数据库是5版本,而springboot仲裁版本是8.0.22,操作方式如下

 第一种是在poom.xml中因依赖时直接写明version版本 

 第二种是在poom.xml中的properties里直接声明所需版本

4.在学习码神之路博客系统实战时,发现的小bug,在编写pojo类时,如果数据类型使用了int类型,使用mp更新数据时,虽然只设置某个字段来更新,但这时更新后,数据库其他字段将被置为0!!!

例如下面使用mp更新数据

package com.lum.blog.service.Impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lum.blog.dao.mapper.ArticleMapper;
import com.lum.blog.dao.pojo.Article;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author lum
 * @date 2021/9/3
 */

@Component
public class ThreadService {


    //期望此操作在线程池中 执行 不会影响主线程


    @Async("taskExecutor")
    public void updateArticleViewCount(ArticleMapper articleMapper, Article article) {

        int viewCounts = article.getViewCounts();
        Article articleUpdate = new Article();
        articleUpdate.setViewCounts(viewCounts+1);

        LambdaUpdateWrapper<Article> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Article::getId,article.getId());
        // 设置一个为了在多线程的条件下 线程安全
        updateWrapper.eq(Article::getViewCounts,viewCounts);
        // update article set view_count = 100 where view_count =99 and id = 1
        articleMapper.update(articleUpdate, updateWrapper);

        try {
            Thread.sleep(2000);
            System.out.println("更新完成!");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}

打印出的sql语句为

 而我们的本意是只想更新一个数据

解决方法是将所有的int类型替换为Interger类型

package com.lum.blog.dao.pojo;

import lombok.Data;
/*
博客管理
 */
@Data
public class Article {

    public static final Integer Article_TOP = 1;

    public static final Integer Article_Common = 0;

    private Long id;

    private String title;

    private String summary;

    private Integer commentCounts;

    private Integer viewCounts;

    /**
     * 作者id
     */
    private Long authorId;
    /**
     * 内容id
     */
    private Long bodyId;
    /**
     *类别id
     */
    private Long categoryId;

    /**
     * 置顶
     */
    private Integer weight;


    /**
     * 创建时间
     */
    private Long createDate;
}



5.带路径参数的接口怎么接收???

 如下所示,使用@PathVariable("id")

6.采用分布式id,导致传到前端的数据无法解析,导致精度损失

 因为分布式id 的Long过长前端解析精度损失,会将值改变,需要进行Json序列化

 问题就得以解决

 @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

7.mapper无法识别??????

今天,博主在敲springboot实战的时候,因为mybits-plus实现多表查询并不是很直观,博主使用了mybits,却遇到mapper无法识别的问题,反复检查代码并没有问题,翻阅csdn各种方法,也没得到解决 

 

网上给到的解决方法是,配置文件加xml的路径配置,也没奏效

server.port=8888
spring.application.name=qh_

#数据库的设置
spring.datasource.url=jdbc:mysql://localhost:3306/qhcommunity?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC
spring.datasource.username=root
spring.datasource.password=zheshao999
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver



#Mybaties-plus配置
# 打印sql语句
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#声明数据库字段前缀都为ms_
mybatis-plus.global-config.db-config.table-prefix=qh_
mybatis-plus.type-aliases-package=com/atqh/qhcommunity/dao/pojo
mybatis-plus.mapper-locations=classpath:com/atqh/qhcommunity/dao/mapper/*.xml

仔细考虑了两个多小时,终于发现了问题,原来是rescourse目录下不能连续创建文件

对比前后的图片,不难发现问题的出处!!!!!!!!!!!!!

 

                                     

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值