【发布时间】:2022-01-21 20:25:18
【问题描述】:
界面CompanyMasterInterface:
@Query(nativeQuery = true,
value ="SELECT s.* from companymaster as s WHERE s.name = ':title'")
public CompanyMaster ByNameOrDaName(@Param("title") String title);
服务CompanyMasterServiceImpl:
@Autowired
private CompanyMasterInterface services;
public CompanyMaster ByNameOrDaName(String title) {
return services.ByNameOrDaName(title);
}
控制器: 例如名称是“Taj”并且它存在于数据库中。
@Autowired
private CompanyMasterServiceImpl companyImpl;
////now the class is as following
CompanyMaster cmp = companyImpl.ByNameOrDaName("Taj");
if(cmp == null){
System.out.println("there is no data");
} else {
System.out.println("there is data");
}
问题是为什么我总是得到 {cmp is null} 而 Taj 在数据库中。
【问题讨论】:
-
我很惊讶您发布的代码甚至可以编译。 “泰姬陵”不是有效的 Java
-
它是更新,"",因为我曾经传递这个动态,所以我在发布时忘记更正它
-
去掉
:title周围的单引号 -
是的,没错,我们都在同一时间得到它,哈哈
标签: java mysql spring spring-boot