将对象属性作为参数传递 java spring
Pass an object attribute as Parameter java spring
我可以从我的存储库中将属性作为参数传递给方法吗?
示例:
@Query("select a from Account a where :attr = :value")
public Page<Account> searchByFilter(@Param("attr")
String attribute,@Param("value")String value,Pageable pageable);
调用示例:
searchByFilter("status","Active",....);
谢谢
不,不可能。
基本上您的查询可以被编译并成功执行,但是它不会按照您喜欢的方式进行翻译。
最后你会sql这样
select a.* from account a where 'status' = 'Active';
注意:状态被转换为字符串值,而不是列名。
我可以从我的存储库中将属性作为参数传递给方法吗?
示例:
@Query("select a from Account a where :attr = :value")
public Page<Account> searchByFilter(@Param("attr")
String attribute,@Param("value")String value,Pageable pageable);
调用示例:
searchByFilter("status","Active",....);
谢谢
不,不可能。
基本上您的查询可以被编译并成功执行,但是它不会按照您喜欢的方式进行翻译。
最后你会sql这样
select a.* from account a where 'status' = 'Active';
注意:状态被转换为字符串值,而不是列名。