问题是这样的
我想动态的切换一下字段名,所以我是用变量A来表示动态切换的字段名,用变量B来接收所查询的内容
但查询结果为空
问题相关代码
接口
//模糊查询
@Select("SELECT * FROM sci_user_info WHERE " +
"sui_name LIKE CONCAT('%',#{sui_name},'%') AND " +
"sui_start_date LIKE CONCAT('%',#{sui_start_date},'%') AND " +
"CONCAT(#{sui_others}) LIKE CONCAT('%',#{sui_other},'%')")
@Results({
...
})
List<User> findFuzzy(String sui_name, String sui_start_date, String sui_others, String sui_other);
方法
//模糊查询
@GetMapping("/getFuzzy")
public Result<List<User>> findFuzzy(@RequestParam(value = "sui_name") String sui_name,
@RequestParam(value = "sui_start_date") String sui_start_date,
@RequestParam(value = "sui_others") String sui_others,
@RequestParam(value = "sui_other") String sui_other){
List<User> Fuzzy = demoUserMapper.findFuzzy(sui_name, sui_start_date, sui_others, sui_other);
Result<List<User>> result = new Result<>();
result.setCode(200);
result.setMessage("模糊查询【" + sui_name + "】【" + sui_start_date + "】【" + sui_others + "】【" + sui_other + "】成功");
result.setResult(Fuzzy);
return result;
}
运行结果及内容
{
"success": true,
"message": "模糊查询【黄某人】【2021-12-17】【sui_qq】【1a1a1a1a】成功",
"code": 200,
"result": [],
"timestamp": 1640158662932
}
我的尝试过的方法
//这是我尝试过的语句,但还是不行
@Select("SELECT sui_name, sui_start_date,CONCAT(#{sui_others}) FROM sci_user_info WHERE " +
"sui_name LIKE CONCAT('%',#{sui_name},'%') AND " +
"sui_start_date LIKE CONCAT('%',#{sui_start_date},'%') AND " +
"CONCAT(#{sui_others}) LIKE CONCAT('%',#{sui_other},'%')")
我想要达到的结果
能根据CONCAT(#{sui_others})获取到的字段名来查询CONCAT('%',#{sui_other},'%')获取的值