好想住在海边 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条回答 默认 最新

  • 路漫漫,其修远兮 2024-02-22 17:55
    关注

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

    评论

报告相同问题?

问题事件

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