hayley-liu 2022-02-18 11:10 采纳率: 0%
浏览 370

Mybatis update database java.lang.NullPointerException

问题遇到的现象和发生背景

我在com.fii.gxback.mould.manualmapping.mapper.MouldCountMapper里面增加了一个function updateLastInspectionCountList ,相应的MouldCountMapper.xml里也增加了,但执行报 update database java.lang.NullPointerException

问题相关代码,请勿粘贴截图

这是Mapper:

package com.fii.gxback.mould.manualmapping.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fii.gxback.mould.mpmapping.entity.MouldObj;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;



public interface MouldCountMapper extends BaseMapper<MouldObj> {
   /* @Update("update mould_obj set " +
            "mould_obj.last_count = mould_obj.last_count + #{lastCount}," +
            "mould_obj.update_time = now() " +
            "where mould_obj.mould_std_union_id = #{unionId} " +
            " and mould_obj.last_count_time &lt;= #{lastCountTime} " +
            " and mould_obj.domain = #{domain}")*/
    void updateLastCount(@Param("lastCount") Integer lastCount,
                         @Param("unionId") String unionId,
                         @Param("lastCountTime") LocalDateTime lastCountTime,
                         @Param("domain") String domain);

    /*@Update("update mould_obj set " +
            "mould_obj.last_count = mould_obj.last_count + #{lastCount}," +
            "mould_obj.update_time = now() " +
            "where mould_obj.mould_std_union_id IN " +
            "                <foreach collection=\"unionIdList\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">" +
            "                    #{item} " +
            "                </foreach>" +
            " AND mould_obj.domain = #{domain}")*/
    void updateLastCountList(@Param("lastCount") Integer lastCount,
                             @Param("unionIdList") List<String> unionIdList,
                             @Param("lastCountTime") LocalDateTime lastCountTime,
                             @Param("domain") String domain);

    /*@Select("SELECT * FROM mould_obj WHERE mould_obj.last_count >= #{lastInspectionCount} " +
            "AND mould_obj.domain = #{domain} " +
            "AND mould_obj.mould_std_union_id =  #{mouldStdUnionId};")*/
    MouldObj selectCountList(@Param("lastInspectionCount") Integer lastInspectionCount,
                             @Param("mouldStdUnionId") String mouldStdUnionId,
                             @Param("domain") String domain);

    /*@Update("update mmould_obj set " +
            "mould_obj.last_inspection_count = #{lastInspectionCount}, " +
            "mould_obj.update_time = now() " +
            "where mould_obj.last_count >= #{lastInspectionCount} " +
            "AND mould_obj.domain = #{domain} " +
            "AND mould_obj.mould_std_union_id = #{mouldStdUnionId}")*/
    void updateLastInspectionCountList(@Param("lastInspectionCount") Integer lastInspectionCount,
                                       @Param("mouldStdUnionId") String mouldStdUnionId,
                                       @Param("updateTime") LocalDateTime updateTime,
                                       @Param("domain") String domain);
}

这是xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fii.gxback.mould.manualmapping.mapper.MouldCountMapper">
    <resultMap type="com.fii.gxback.mould.mpmapping.entity.MouldObj" id="MouldStdRM">
        <id property="id" column="id"/>
        <result property="topLimit" column="top_limit"/>
        <result property="domain" column="domain"/>
        <result property="lastCount" column="last_count"/>
        <result property="mouldStdUnionId" column="mould_std_union_id"/>
        <result property="lastCountTime" column="last_count_time"/>
        <result property="lastInspectionCount" column="last_inspection_count"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <update id="updateLastCount" parameterType="com.fii.gxback.mould.mpmapping.entity.MouldObj">
        UPDATE mould_obj
        <set>
            <if test="lastCount != null">
                mould_obj.last_count = mould_obj.last_count + #{lastCount},
            </if>
            mould_obj.update_time = now()
        </set>
        <where>
            <if test="unionId != null">
                mould_obj.mould_std_union_id = #{unionId}
            </if>
            <if test="lastCountTime != null">
                AND
                mould_obj.last_count_time &lt;= #{lastCountTime}
            </if>
            <if test="domain != null">
                AND
                mould_obj.domain = #{domain}
            </if>
        </where>
    </update>

    <update id="updateLastCountList" parameterType="com.fii.gxback.mould.mpmapping.entity.MouldObj">
        UPDATE mould_obj
        <set>
            <if test="lastCount != null">
                mould_obj.last_count = mould_obj.last_count + #{lastCount},
                mould_obj.update_time = now(),
            </if>
            <if test="lastCountTime != null">
                mould_obj.last_count_time = #{lastCountTime}
            </if>
        </set>
        <where>
            <if test="lastCountTime != null">
                (mould_obj.last_count_time is null or mould_obj.last_count_time &lt;= #{lastCountTime})
            </if>
            <if test="domain != null">
                AND
                mould_obj.domain = #{domain}
            </if>
            <if test="unionIdList != null">
                AND (
                mould_obj.mould_std_union_id IN
                <foreach collection="unionIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
                )
            </if>
        </where>
    </update>
    <select id="selectCountList" resultType="com.fii.gxback.mould.mpmapping.entity.MouldObj">
     SELECT * FROM mould_obj WHERE mould_obj.last_count >= #{lastInspectionCount}
        AND mould_obj.domain = #{domain}
        AND mould_obj.mould_std_union_id =  #{mouldStdUnionId};
</select>

    <update id="updateLastInspectionCountList" parameterType="com.fii.gxback.mould.mpmapping.entity.MouldObj">
        UPDATE mould_obj
        <set>
            <if test="lastInspectionCount != null">
                mould_obj.last_inspection_count = #{lastInspectionCount},
            </if>
            <if test="updateTime != null">
                mould_obj.update_time = #{updateTime}
            </if>
        </set>
        <where>
            <if test="lastInspectionCount != null">
                mould_obj.last_count >= #{lastInspectionCount}
            </if>
            <if test="domain != null">
                AND
                mould_obj.domain = #{domain}
            </if>
            <if test="mouldStdUnionId != null">
                AND
                mould_obj.mould_std_union_id = #{mouldStdUnionId}
            </if>
        </where>
    </update>

</mapper>

这是实体BEAN:

package com.fii.gxback.mould.mpmapping.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author wt
 * @since 2021-08-12
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class MouldObj implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 自增主键id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 模具+基准联合id
     */
    private String mouldStdUnionId;

    /**
     * 上一次累计打点次数
     */
    private Integer lastCount;

    /**
     * 冲压次数上限
     */
    private Integer topLimit;

    /**
     * 保留字段-条目创建时间
     */
    private LocalDateTime createTime;

    /**
     * 保留字段-条目更新时间
     */
    private LocalDateTime updateTime;

    private String domain;

    /**
     * 上一次启动保养计划累计打点次数
     */
    private Integer lastInspectionCount;

    /**
     * 上一次累计打点次数记录时间
     */
    private LocalDateTime lastCountTime;


}


运行结果及报错内容

com.fii.gxback.common.exception.ApiException: setLastInspectionCountList失败,

Error updating database. Cause: java.lang.NullPointerException

The error may exist in com/fii/gxback/mould/manualmapping/mapper/MouldCountMapper.xml

The error may involve com.fii.gxback.mould.manualmapping.mapper.MouldCountMapper.updateLastInspectionCountList

The error occurred while executing an update

Cause: java.lang.NullPointerException

at com.fii.gxback.mould.service.MouldCountService.setLastInspectionCountList(MouldCountService.java:183)
at com.fii.gxback.mould.service.MouldCountService.checkCountWithTopLimit(MouldCountService.java:161)
at com.fii.gxback.mould.service.MouldCountService$$FastClassBySpringCGLIB$$dee4ef74.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.fii.gxback.mould.service.MouldCountService$$EnhancerBySpringCGLIB$$13534f21.checkCountWithTopLimit(<generated>)
at com.fii.gxback.mould.amqp.listener.MouldGroupAccountGetCountTriggerListener.updateAllLastCountByMouldId(MouldGroupAccountGetCountTriggerListener.java:111)
at com.fii.gxback.mould.amqp.listener.MouldGroupAccountGetCountTriggerListener.factor(MouldGroupAccountGetCountTriggerListener.java:72)
at com.fii.gxback.mould.amqp.listener.MouldGroupAccountGetCountTriggerListener.process(MouldGroupAccountGetCountTriggerListener.java:51)
at com.fii.gxback.mould.amqp.listener.MouldGroupAccountGetCountTriggerListener$$FastClassBySpringCGLIB$$68070d5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685)
at com.fii.gxback.mould.amqp.listener.MouldGroupAccountGetCountTriggerListener$$EnhancerBySpringCGLIB$$9be6d8f5.process(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120)
at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:53)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:220)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:148)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:133)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1579)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1498)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at brave.spring.rabbit.TracingRabbitListenerAdvice.invoke(TracingRabbitListenerAdvice.java:101)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at org.springframework.amqp.rabbit.listener.$Proxy270.invokeListener(Unknown Source)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1486)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1477)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1421)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:963)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:913)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:81)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1284)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1190)
at java.lang.Thread.run(Thread.java:748)
我的解答思路和尝试过的方法

mapper 里面直接写SQL语句或者在XML这个出错的SQL里直接用固定的好的SQL语句都报这个错误

我想要达到的结果

数据可以更新成功。

  • 写回答

4条回答 默认 最新

  • zcl_1991 2022-02-18 11:25
    关注

    NPE你倒是截图截重点啊,

    img


    全是无用信息

    评论

报告相同问题?

问题事件

  • 创建了问题 2月18日

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用