我已使用 JPA/Hibernate 将数据库连接到我的主 Java 应用程序。我可以通过 Spring boot 项目在 Microsoft SQL 表中添加/删除项目。尽管当需要查看表中的所有内容时,我收到错误。我在下面附加了一些与该项目相关的更多代码。
实体类:
import javax.persistence.*;
@Entity
@Table(name = "taddm")
public class AVSApplication {
@Id
@Column(name = "appcode")
private String mAppCode;
@Column(name = "acro")
private String mAcronym;
@Column(name = "appname")
private String mAppName;
//Constructor
public AVSApplication(String mAppCode, String mAcronym, String mAppName) {
super();
this.mAppCode = mAppCode;
this.mAcronym = mAcronym;
this.mAppName = mAppName;
}
//Default Constructor
public AVSApplication () {
}
//Getters
public String getmAppCode() {
return mAppCode;
}
public String getmAcronym() {
return mAcronym;
}
public String getmAppName() {
return mAppName;
}
//Setters
public void setmAcronym(String mAcronym) {
this.mAcronym = mAcronym;
}
public void setmAppCode(String mAppCode) {
this.mAppCode = mAppCode;
}
public void setmAppName(String mAppName) {
this.mAppName = mAppName;
}
}
控制器:
//Select
@GetMapping("/select-me")
public String selectApplication() {
System.out.println(mAppRepo.findAll());
System.out.println(mAppRepo.findById("3A0"));
return "tier";
}
错误:
Hibernate: select avsapplica0_.appcode as appcode1_0_, avsapplica0_.acro as acro2_0_, avsapplica0_.appname as appname3_0_ from taddm avsapplica0_
[]
Hibernate: select avsapplica0_.appcode as appcode1_0_0_, avsapplica0_.acro as acro2_0_0_, avsapplica0_.appname as appname3_0_0_ from taddm avsapplica0_ where avsapplica0_.appcode=?
Optional.empty
回购协议:
@Repository
public interface AppRepository extends JpaRepository<AVSApplication, String>{
@Override
List<AVSApplication> findAll();
}
表名称:
appcode (primary key)
acro
appname
噜噜哒
守着一只汪
波斯汪
相关分类