gpt4 book ai didi

java - JPA 自定义查询仅返回某些值

转载 作者:行者123 更新时间:2023-12-02 02:00:28 25 4
gpt4 key购买 nike

我做了一些测试,但找不到问题所在。

我正在执行一些自定义查询,我只需要从数据库返回一些数据,问题是它只返回某些列的值。

My query should return this:

但它只返回这个:

[
{
"nome": "ALAN ",
"empresa": "data",
"ultimaSaida": null,
"grupoUsuarios": null,
"epc": null,
"areaControleAtual": null
},
{
"nome": "ALEXANDRE ",
"empresa": "data",
"ultimaSaida": null,
"grupoUsuarios": null,
"epc": null,
"areaControleAtual": null
},
{
"nome": "BRUNO ",
"empresa": "data",
"ultimaSaida": null,
"grupoUsuarios": null,
"epc": null,
"areaControleAtual": null
}

只有字段 nomeepc(null 正确)empresa 可以。

我相信问题出在我的自定义查询中,但我不知道出了什么问题。

我的自定义查询:

public interface EmployeesRepository extends JpaRepository<Employees, Integer> {

@Query(value = "SELECT * FROM USRAPP.ACESSO_LISTA WHERE 'FAB' = SUBSTR(area_controle_atual, 1, 3)", nativeQuery = true)
List<EmployeesNecessaryData> findEmployeesByFactory();

}

我的界面:

public interface EmployeesNecessaryData {
String getNome();

String getUltimaSaida();

String getEpc();

String getAreaControleAtual();

String getGrupoUsuarios();

String getEmpresa();


}

员工类:

@Table(name = "ACESSO_LISTA", schema = "USRAPP")
public class Employees {

@Id
@GeneratedValue
@Column(name = "ID_USUARIO")
private Integer id;
@Column(name = "NOME")
private String nome;
@Column(name = "EMPRESA")
private String empresa;
@Column(name = "ULTIMA_SAIDA")
private String ultimaSaida;
@Column(name = "AREA_CONTROLE_ATUAL")
private String areaControleAtual;
@Column(name = "GRUPO_USUARIOS")
private String grupoUsuarios;
@Column(name = "EPC")
private String epc;

public Employees(String nome, String areaControleAtual, String empresa, String grupoUsuarios, String ultimaSaida) {
this.nome = nome;
this.areaControleAtual = areaControleAtual;
this.empresa = empresa;
this.grupoUsuarios = grupoUsuarios;
this.ultimaSaida = ultimaSaida;
}

public Employees(String nome, String empresa) {
this.nome = nome;
this.empresa = empresa;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getEmpresa() {
return empresa;
}

public void setEmpresa(String empresa) {
this.empresa = empresa;
}

public String getUltimaSaida() {
return ultimaSaida;
}

public void setUltimaSaida(String ultimaSaida) {
this.ultimaSaida = ultimaSaida;
}

public String getAreaControleAtual() {
return areaControleAtual;
}

public void setAreaControleAtual(String areaControleAtual) {
this.areaControleAtual = areaControleAtual;
}

public String getGrupoUsuarios() {
return grupoUsuarios;
}

public void setGrupoUsuarios(String grupoUsuarios) {
this.grupoUsuarios = grupoUsuarios;
}

public String getEpc() {
return epc;
}

public void setEpc(String epc) {
this.epc = epc;
}
}

我的端点调用,返回 JSON:

@RequestMapping(value = "start", method = RequestMethod.GET)
@ResponseBody
public List<EmployeesNecessaryData> startList(@RequestParam("sector") String sector) {

return employeesRepository.findEmployeesByFactory();

}

提前致谢。

最佳答案

  • 尝试此查询
  • 根据您的需要更改以下内容
  • 当您发布新问题时请描述所有内容,因为它会帮助帮助你
public interface EmployeesRepository extends JpaRepository<Employees, Integer> {

@Query(
value =
"select c from c.USRAPP.ACESSO_LISTA where c.'FAB' = SUBSTRING(c.area_controle_atual, 1, 3)")
List<EmployeesNecessaryData> findEmployeesByFactory();


}

关于java - JPA 自定义查询仅返回某些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57377206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com