汪的爱琪 2024-02-22 17:07 采纳率: 67.5%
浏览 10
已结题

springboot的参数传递问题


   @GetMapping("/find")
    public Result<List<Article>> selectArticle(@RequestBody @RequestParam(required = false) Article article)
    {
        return Result.success(articleService.selectArticle(article));
    }

我加上 @RequestParam(required = false) 当我前端这样写

{
    "author" : "李白"
}

好像就不能根据将作者放入article文章类中封装去查了,我的本意是前端什么都不传根据文章所有者的id查询所有文章,如果前端传入值就根据前端传递的值sql拼接动态查询

  <select id="selectArticle" resultType="com.codeCart.pojo.Article">
        select * from article
        <where>
            <if test="title != null">
                and title = #{title}
            </if>
            <if test="author != null">
                and author = #{author}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="updatedAt != null">
                and updated_at = #{updatedAt}
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
        </where>
    </select>


  • 写回答

4条回答 默认 最新

  • guicai_guojia 2024-02-22 17:55
    关注

    你要的逻辑 需要后端代码 逻辑处理一下就ok了

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月8日
  • 修改了问题 2月22日
  • 创建了问题 2月22日

悬赏问题

  • ¥15 有人会用py或者r画这种图吗
  • ¥15 MOD04_3K图像预处理
  • ¥15 [VASP]关于超胞大小和k 点网格的收敛性测试
  • ¥15 pip下载paddle2onnx离谱错误
  • ¥60 db2move nlzxams import 导出db2备份数据报错
  • ¥15 关于#python#的问题:全文总结功能咨询
  • ¥15 俄罗斯方块中无法同时消除多个满行
  • ¥15 使用gojs3.0,如何在nodeDataArray设置好text的位置,再go.TextBlock alignment中进行相应的改变
  • ¥15 psfusion图像融合指标很低
  • ¥15 银河麒麟linux系统如何修改/etc/hosts权限为777