开发问题收集录

1 SpringBoot整合MybatisPlus

在这里插入图片描述
起初我只导了这三个依赖,但是运行的时候会给我报错
在这里插入图片描述
多加一个依赖就好了

    <!--mybatis-plus 启动项依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatisplus-spring-boot-starter</artifactId>
        </dependency>
        <!--mybatis-plus 官网给的依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.4.2</version>
        </dependency>
        <!--boot整合mybatis       新增的-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>
        <!--mybatis-plus的相关注解-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-annotation</artifactId>
            <version>3.3.2</version>
        </dependency>

此依赖包含上面依赖

		<!-- 也可以直接导入这一个依赖,上面的都不需要-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
        </dependency>

2 RestarClassLoader 项目重新加载就好

3.MySQLNonTransientConnectionException

.
在这里插入图片描述
报错原因不是用户名密码问题
在这里插入图片描述
修改后即可正常访问数据库
在这里插入图片描述

4.Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

解决:原本是想做个聚合工程的,最后把子模块给删了.需要在项目的pom文件中删除

 <packaging>pom</packaging>

在这里插入图片描述

5:Field ‘××××’ doesn’t have a default value

原因在于数据库的设置,字段设置not null,但是没有给默认值.字符这个类型的默认为null;

6.resources下面的mapper映射文件创建时,多层级必须带 / 比如 aa/bb/cc 不能用.(点)

7.stream转map健重复会报错,需要加覆盖条件

        Map<String, String> collect = list.stream()
                .collect(Collectors.toMap(User::getUsername, User::getPassword));
        System.out.println(collect);

异常信息

Exception in thread "main" java.lang.IllegalStateException: Duplicate key 张三 (attempted merging values 123 and 123)

加覆盖条件

        Map<String, String> collect = list.stream()
                .collect(Collectors.toMap(User::getUsername, User::getPassword,(k1,k2)->k1));
        System.out.println(collect);

如果k1,k2相同,那么取k1的值做健

8 mybatis的reslutMapper

	//javaType 元素类型    ofType集合的元素类型
    <association property="对象名" javaType="一对一"></association>
    <collection property="对象名" ofType="一对多"></collection>

9 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [user]: would dispatch back to the current handler URL [/user] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause

@RequestMapping("user")
@RestController
public class ShortVideoOrderController {

@Controller改成@RestController
一个返回的是字符串,一个返回的是Json对象

10 异常就不去重现了.是sql执行时发现表找不到

@Data
@TableName("指定表名")
public class ShortVideoOrderEntity implements Serializable {
    /**
     * 订购的订单id
     */
    @TableId
    private String orderId;

mybatis-plus中,实体类需要指定表名/也是好久没写过,一直报表找不到.汗

11 执行sql语句时,会报某某字段不存在.很有可能是拼写错误

12批量插入报错

在这里插入图片描述
在这里插入图片描述
原因就是open 和 close.open和close通常是放在select的in的关键字后面,表示括号

13事务提交

在开发中碰到过一次问题.事务开启.我插入了数据库,但是后面提供给外部项目的接口的需要查询该数据实现回调.但是此时开启的事务导致数据并未提交

    @Autowired
    private PlatformTransactionManager txManager;        
//开启新事物.并且手动提交.在mapper接口上开启,编译不给过
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionStatus status = txManager.getTransaction(def);
        *********.insert(renew);
        txManager.commit(status);

14 Mockito测试私有方法未生效

@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
@PrepareForTest(测试的类.class)

 MemberModifier.stub(MemberMatcher.method(测试的类.class, "方法名",OrderInfoVo.class,long.class,long.class)).toReturn("s");

测了很多次都是进入了私有方法内部,后面发现是@Test的包不对,
应该导入import org.junit.Test;

15 nacos未能发现服务

根因是自己写的demo,没有导入web依赖.

16mybatis的分页插件失效(查询的是所有)

引入插件依赖
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency>
mybatis的核心配置文件,mybatis-config.xml
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!--分页参数合理化  -->
            <property name="reasonable" value="true"/>
        </plugin>
    </plugins>
核心代码,分页的条数这种数据为了调试我写死了,请勿模仿
    @Override
    public RestBase<PageInfo<Student>> studentList(CreateStudentVo createStudentVo) {
        PageHelper.startPage(1,5);
        List<Student> student = studentMapper.studentList(createStudentVo);
         PageInfo<Student> pageInfo=new PageInfo<>(student);
        return new RestBase<>(pageInfo);
    }
配置文件
mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.anxing.love.pojo
  # 将下划线映射到小驼峰
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

查询所有的原因是核心配置文件未被读取.需要在yml文件里添加config-location.而且他和configuration只能存在一个.

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.anxing.love.pojo
#  # 将下划线映射到小驼峰
#  configuration:
#    map-underscore-to-camel-case: true
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  config-location: classpath:mybatis-config.xml

17maven依赖全部爆红,但是仓库里都有

最近做的一个内网项目.代码拉取下来,pom文件大部分都是正常的.但是代码里的导包全都是爆红的.除了jdk自带的一些包.maven仓库里的包都是有的,排查了好久.需要勾选一下离线工作
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值