我是 Spring Boot 和休眠的新手。在这里,我正在尝试运行基于搜索的可选参数查询,我可以在其中按名称、国家/地区等进行搜索。如果我将此字段保留为空,则查询应全部列出。但问题是我的方法是返回所有数据而忽略我的搜索参数。我的模型课看起来像
@Entity(name="MLFM_ORDER_OWNER")
public class ModelOrderOwner {
@Id @GenericGenerator(name = "custom_sequence", strategy =
"com.biziitech.mlfm.IdGenerator")
@GeneratedValue(generator = "custom_sequence")
@Column(name="ORDER_OWNER_ID")
private Long orderOwnerId;
@Column(name="OWNER_NAME")
private String ownerName;
@OneToOne
@JoinColumn(name="BUSINESS_TYPE_ID")
private ModelBusinessType businessTypeId;
@Column(name="SHORT_CODE")
private String shortCode;
@ManyToOne
@JoinColumn(name="OWNER_COUNTRY")
private ModelCountry ownerCountry;
// getter setter..
我的存储库界面看起来像
public interface OrderOwnerRepository extends
JpaRepository<ModelOrderOwner,Long>{
@Query("select a from MLFM_ORDER_OWNER a where a.businessTypeId.typeId=coalsec(:typeId,a.businessTypeId.typeId) and a.ownerCountry.countryId=coalsec(:countryId,a.ownerCountry.countryId) and a.ownerName LIKE %:name and a.shortCode LIKE %:code")
public List <ModelOrderOwner> findOwnerDetails(@Param("typeId")Long typeId,@Param("countryId")Long countryId,@Param("name")String name,@Param("code")String code);
}
这是我在控制器中的方法
@RequestMapping(path="/owners/search")
public String getAllOwner(Model model,@RequestParam("owner_name") String name,@RequestParam("shortCode") String code,
@RequestParam("phoneNumber") String phoneNumber,@RequestParam("countryName") Long countryId,
@RequestParam("businessType") Long typeId
) {
model.addAttribute("ownerList",ownerRepository.findOwnerDetails(typeId, countryId, name, code));
return "data_list";
}
任何人都可以在这方面帮助我吗?请?
月关宝盒
湖上湖
杨魅力
相关分类