idea后端报错
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7a141071]
全局异常
2023-06-18 10:50:30.433 WARN 28700 --- [nio-8000-exec-7] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mail_1.mail.mapper.SmallTypeMapper.findById
The error may exist in file [C:\Users\leo\Desktop\商城\后端架构项目\mail\target\classes\mybatis\mapper\ProductMapper.xml]
The error may involve com.mail_1.mail.mapper.ProductMapper.list
The error occurred while handling results
SQL: select * from product limit ?,?
Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mail_1.mail.mapper.SmallTypeMapper.findById]
不知道什么原因
ProductMapper.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.mail_1.mail.mapper.ProductMapper">
<resultMap id="productResult" type="com.mail_1.mail.entity.Product">
<association property="type" column="typeId" select="com.mail_1.mail.mapper.SmallTypeMapper.findById"></association>
</resultMap>
<select id="list" parameterType="Map" resultMap="productResult">
select * from product
<where>
<if test="name!=null and name!='' ">
and name like concat('%',#{name},'%')
</if>
</where>
<if test="start!=null and pageSize!=null ">
limit #{start},#{pageSize}
</if>
</select>
<select id="getTotal" parameterType="Map" resultType="Long">
select count(*) from product
<where>
<if test="name!=null and name!='' ">
and name like concat('%',#{name},'%')
</if>
</where>
</select>
<insert id="add" parameterType="com.mail_1.mail.entity.Product">
insert into product values(null,#{name},#{price},#{stock},#{proPic},#{hot},#{swiper},#{swiperPic},#{swiperSort},#{type.id},null,#{productIntroImgs},#{productParaImgs},#{description});
</insert>
<update id="update" parameterType="com.mail_1.mail.entity.Product">
update product
<set>
<if test="name!=null and name!=''">
name=#{name},
</if>
<if test="price!=null">
price=#{price},
price=#{price},
</if>
<if test="stock!=null">
stock=#{stock},
</if>
<if test="type!=null and type.id!=null">
typeId=#{type.id},
</if>
<if test="proPic!=null and proPic!=''">
proPic=#{proPic},
</if>
<if test="description!=null and description!=''">
description=#{description},
</if>
<if test="productIntroImgs!=null and productIntroImgs!=''">
productIntroImgs=#{productIntroImgs},
</if>
<if test="productParaImgs!=null and productParaImgs!=''">
productParaImgs=#{productParaImgs},
</if>
<if test="swiperPic!=null and swiperPic!=''">
swiperPic=#{swiperPic},
</if>
<if test="swiperSort!=null">
swiperSort=#{swiperSort},
</if>
</set>
where id=#{id}
</update>
<select id="findById" parameterType="Integer" resultMap="productResult">
select * from product where id=#{id}
</select>
</mapper>
SmallTypeMapper.java文件
findById
package com.mail_1.mail.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mail_1.mail.entity.SmallType;
import java.util.List;
import java.util.Map;
/**
* 商品小类Mapper接口
*/
public interface SmallTypeMapper extends BaseMapper<SmallType> {
List<SmallType> list(Map<String,Object> map);
Long getTotal(Map<String,Object> map);
SmallType findById(Integer id);
}
AdminSmallTypeController.java文件
package com.mail_1.mail.controller.admin;
import com.mail_1.mail.entity.SmallType;
import com.mail_1.mail.entity.PageBean;
import com.mail_1.mail.entity.R;
import com.mail_1.mail.service.IBigTypeService;
import com.mail_1.mail.service.ISmallTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 管理员-商品小类Controller控制器
*/
@CrossOrigin
@RestController
@RequestMapping("/admin/smallType")
public class AdminSmallTypeController {
@Autowired
private ISmallTypeService smallTypeService;
@Autowired
private IBigTypeService bigTypeService;
/**
* 根据条件分页查询
* @param pageBean
* @return
*/
@RequestMapping("/list")
public R list(@RequestBody PageBean pageBean){
System.out.println(pageBean);
Map<String,Object> map=new HashMap<>();
map.put("name",pageBean.getQuery().trim());
map.put("start",pageBean.getStart());
map.put("pageSize",pageBean.getPageSize());
List<SmallType> smallTypeList=smallTypeService.list(map);
Long total=smallTypeService.getTotal(map);
Map<String,Object> resultMap=new HashMap<>();
resultMap.put("smallTypeList",smallTypeList);
resultMap.put("total",total);
return R.ok(resultMap);
}
/**
* 删除
* @param id
* @return
*/
@GetMapping("/delete/{id}")
public R delete(@PathVariable(value = "id")Integer id){
smallTypeService.removeById(id);
return R.ok();
}
/**
* 添加或者修改
* @param smallType
* @return
*/
@RequestMapping("/save")
public R save(@RequestBody SmallType smallType){
smallType.setBigTypeId(smallType.getBigType().getId());
if(smallType.getId()==null || smallType.getId()==-1){
smallTypeService.save(smallType);
}else{
smallTypeService.saveOrUpdate(smallType);
}
return R.ok();
}
** /**
* 根据id查询
* @param id
* @return
*/
@GetMapping("/{id}")
public R findById(@PathVariable(value = "id")Integer id){
SmallType smallType = smallTypeService.getById(id);
smallType.setBigType(bigTypeService.getById(smallType.getBigTypeId()));
Map<String,Object> map=new HashMap<>();
map.put("smallType",smallType);
return R.ok(map);
}**
}