@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>