关于评价功能,每评价一条就会for循环很多条相同的数据

关于评价功能,每评价一条就会for循环很多条相同的数据

https://img1.sycdn.imooc.com//climg/62b98e60099c2b9006320770.jpg

相关代码:

<van-action-sheet v-model:show="state.dialogVisible" :title="book.bookName">
    <van-form ref="evaluationForm">
        <van-cell-group inset>
            <van-rate v-model="form.score" color="#ffd21e" void-icon="star" style="padding: 16px" ></van-rate>
            <van-field
                    v-model="form.content"
                    name="content"
                    placeholder="这里输入评论内容"
                    autocomplete = "off"
                    :rules="[{ required: true, message: '请输入评论内容' }]"
            />
        </van-cell-group>
        <div style="margin: 16px;margin-bottom: 50px">
            <van-button round block type="primary" @click="onSubmit('evaluationForm')">
                提交短评
            </van-button>
        </div>
    </van-form>
</van-action-sheet>

相关代码:

@PostMapping("/evaluate")
public ResponseUtils evaluate(Long memberId,Long bookId,Integer score,String content){
    ResponseUtils resp = null;
    try {
        Evaluation evaluation = evaluationService.evaluate(memberId, bookId, score, content);
        resp = new ResponseUtils().put("evaluation",evaluation);
    }catch (Exception e){
        e.printStackTrace();
        resp = new ResponseUtils(e.getClass().getSimpleName(),e.getMessage());
    }
    return resp;
}

相关代码:

实现类
@Override
public Evaluation evaluate(Long memberId, Long bookId, Integer score, String content) {
    Evaluation evaluation = new Evaluation();
    evaluation.setMemberId(memberId);
    evaluation.setBookId(bookId);
    evaluation.setScore(score);
    evaluation.setContent(content);
    evaluation.setCreateTime(new Date());
    evaluation.setState("enable");
    evaluation.setEnjoy(0);
    evaluationMapper.insert(evaluation);
    return evaluation;
}


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,1、测试同学代码是没有问题的,建议同学查看数据库中短评信息,查看是否是数据库中的问题。

2、也有可能是同学查询的问题,同学也可以将代码反馈到问答区。如下所示:将对应的代码反馈到对应的代码格式中。

https://img1.sycdn.imooc.com//climg/62ba64ca09a9291301260342.jpg

祝学习愉快!

  • https://img1.sycdn.imooc.com//climg/62baa01509304a3015370710.jpg

    这是数据库最新的一条数据,么有看出什么问题

    2022-06-28 14:31:32
  • 同学你好,有可能是同学查询的问题,同学也可以将代码反馈到问答区。如下所示:将对应的代码反馈到对应的代码格式中。

    https://img1.sycdn.imooc.com//climg/62ba64ca09a9291301260342.jpg

    祝学习愉快!

    2022-06-28 15:24:54
  • <?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.imooc.reader.mapper.EvaluationMapper">
        <select id="selectByBookId" parameterType="Long" resultType="java.util.LinkedHashMap">
            select e.*,m.nickname  from evaluation e, member m where e.member_id = e.member_id and e.book_id = #{value} and e.state = 'enable' order by e.create_time desc;
        </select>
    
    </mapper>
    是这里吗mapper
    2022-06-28 23:00:38
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师