相关疑难解决方法(0)

在Java变量和方法名称中使用下划线

即使在今天,我经常在Java变量和方法中看到下划线,例如成员变量(如"m_count"或"_count").据我记忆,在这些情况下使用下划线被Sun称为坏风格.

他们应该使用的唯一地方是常量(比如"public final static int IS_OKAY = 1;"),因为常量应该都是大写而不是驼峰.这里,下划线应该使代码更具可读性.

你认为在Java中使用下划线是不好的风格吗?如果是这样(或不是),为什么?

java naming-conventions

81
推荐指数
9
解决办法
10万
查看次数

如何解决带有下划线变量的 Spring Boot findBy 方法

当我运行以下项目时,我收到以下错误。我该如何修复它?

引起原因:java.lang.IllegalArgumentException:无法为方法公共抽象com.example.pharmanic.model.Rdhs_Hospital_Current_Stock com.example.pharmanic.repositories.Rdhs_Hospital_Current_StockRepository.findBysr_no(java.lang.String)创建查询!未找到 Rdhs_Hospital_Current_Stock 类型的属性 sr!

这是我的Rdhs_Hospital_Current_Stock模型课。

@Entity
@Data
@Table(name = "Rdhs_Hospital_Current_Stock")
public class Rdhs_Hospital_Current_Stock {
    @Id
    private Long batchId;
    private int quantity;
    private String expiredate;

    @ManyToOne
    private Hospital_By_Rdhs hospital_by_rdhs;


    @ManyToOne
    @JoinColumn(name = "sr_no", nullable = false, referencedColumnName = "sr_no")
    private Medicine medicine;


}
Run Code Online (Sandbox Code Playgroud)

sr_no是表的外键Medicine

这是我的Medicine实体:

@Data
@Entity
public class Medicine {
    private @Id String sr_no;

    private String name;
    private String side_effect;
    private String description;

    public Medicine() {
    }

    public Medicine(String sr_no, String …
Run Code Online (Sandbox Code Playgroud)

jpa spring-data-jpa spring-boot

5
推荐指数
1
解决办法
3305
查看次数

Spring JpaRepository使用非常规命名从属性中查找实体

以下用于在Spring 1.5.10.RELEASE中工作,但在Spring 2.0.7.RELEASE中不起作用,我不知道为什么:

实体

@Entity
@Table(name = "locations")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Location {
  // ... unimportant stuff
  @Column(name = "c_locations_id")
  private String cLocationId;
  // ... more unimportant stuff
}
Run Code Online (Sandbox Code Playgroud)

存储库(又名"问题")

@Repository
public interface LocationRepository extends JpaRepository<Location, Long>, JpaSpecificationExecutor<Location> {
  Location findByCLocationId(String cLocationId);
  List<Location> findAllByOrderByCLocationIdAsc();
}
Run Code Online (Sandbox Code Playgroud)

我在上面的代码的Spring 2.0.7.RELEASE下得到的错误是

java.lang.IllegalArgumentException:无法在此ManagedType上找到具有给定名称[CLocationId]的Attribute.

由于其他情况,我无法更改属性的名称,因此我尝试了存储库中方法的不同变体:

  • findBycLocationId - 找不到类型为Location的属性orderBycLocationIdAsc!
  • findByClocationId - 找不到类型位置的属性clocationId!你是说'CLocationId','cLocationId'吗?
  • findByCLocationId - 无法在此ManagedType上找到具有给定名称[CLocationId]的Attribute

它想要什么?!我只是想升级框架......

java spring spring-data-jpa

4
推荐指数
1
解决办法
88
查看次数