这个是控制台不打印错误,但是debug能走进这个方法
本质是当使用反射调用方法时,如果被调用的方法抛出了异常
(比如entity中和dto的类型不一致,插入数据库中起了简易名但是没有全部使用,数据库主键重复插入,数据库外键冲突,数据库主键设置名字错误),
但没有在调用的代码中进行捕获和处理,那么该异常会被封装在一个 `InvocationTargetException` 中,并由 `getTargetException()` 方法返回。
插入数据库中起了简易名但是没有全部使用
我的项目中是sql语句中
<select id="pageQuery" resultType="com.sky.vo.jisuanji.StudentVO">
select
s.id AS studentId,s.openid, s.username, s.studentname, s.password,
s.user_type, s.phone, s.sex,s.id_number, s.avatar,s.status,
s.create_time, s.update_time, s.create_user, s.update_user
, c.class_id, c.class_name
from
student s
LEFT JOIN class c ON s.class_id = c.class_id
<where>
<if test="studentId != null">
and s.id = #{studentId}
</if>
<if test="studentname != null and studentname != ''">
and s.studentname like concat('%',#{studentname},'%')
</if>
<if test="classId != null">
and class_id = #{classId}
</if>
<if test="className != null and className != ''">
AND class_name LIKE CONCAT('%', #{className}, '%')
</if>
</where>
order by s.create_time desc
</select>
连表查询中的class_id和class_name没有+上c.导致的转换异常
<select id="pageQuery" resultType="com.sky.vo.jisuanji.StudentVO">
select
s.id AS studentId,s.openid, s.username, s.studentname, s.password,
s.user_type, s.phone, s.sex,s.id_number, s.avatar,s.status,
s.create_time, s.update_time, s.create_user, s.update_user
, c.class_id, c.class_name
from
student s
LEFT JOIN class c ON s.class_id = c.class_id
<where>
<if test="studentId != null">
and s.id = #{studentId}
</if>
<if test="studentname != null and studentname != ''">
and s.studentname like concat('%',#{studentname},'%')
</if>
<if test="classId != null">
and c.class_id = #{classId}
</if>
<if test="className != null and className != ''">
AND c.class_name LIKE CONCAT('%', #{className}, '%')
</if>
</where>
order by s.create_time desc
</select>
改成这样后操作成功
数据库主键设置名字错误
course
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Course implements Serializable {
//主键
private Long courseId;
// 课程名
private String courseName;
....
}
service层中
// 课程名
private String courseName;
//course表插入成功
Long id = null;
courseMapper.insert(course);
log.info("-------------course表插入成功",course);
id = course.getCourseId();
mapper
@AutoFill(value = OperationType.INSERT)
Long insert(Course course);
sql
注意,这里的keyProperty在course中没有,有时也debug走进v4错误,同时会在控制台打印
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into course
(name,category,is_approved,create_time,update_time,teacher_id
,teacher_name,create_user,update_user)
values
(#{courseName},#{category},#{isApproved},#{createTime},#{updateTime},#{teacherId}
,#{teacherName},#{createUser},#{updateUser})
</insert>