闲幻 2023-06-18 11:15 采纳率: 0%
浏览 25

idea后端报错,语句可能存在语法错误。需要检查 Mapper 文件和 SQL 查询语句是否正确,并确保正确加载相关文件

idea后端报错

img

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);
    }**
}

  • 写回答

1条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2023-06-18 11:30
    关注

    你这里不是返回一个SmallType 么,

    img


    mapper中返回的是这个?

    img

    img

    评论

报告相同问题?

问题事件

  • 创建了问题 6月18日

悬赏问题

  • ¥15 c#转安卓 java html
  • ¥15 os.listdir文件路径找不到
  • ¥15 使用gojs3.0,如何在nodeDataArray设置好text的位置,再go.TextBlock alignment中进行相应的改变
  • ¥15 psfusion图像融合指标很低
  • ¥15 银河麒麟linux系统如何修改/etc/hosts权限为777
  • ¥50 医院HIS系统代码、逻辑学习
  • ¥30 docker离线安装mysql报错,如何解决?
  • ¥15 构建工单的总账影响在哪里查询或修改
  • ¥15 三个简单项目写完之后有重赏之后联系我
  • ¥15 python报内存不能read错误