当前位置: 首页 > 知识库问答 >
问题:

按field Spring Boot查找

仲学真
2023-03-14
@Entity
@Table(name="paciente")
public class Paciente {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;

    @Column(name="rut_num")
    private int rut_num;

    @Column(name="nombre")
    private String nombre;

    @Column(name="a_pat")
    private String a_pat;

    @Column(name="a_mat")
    private String a_mat;

    //getters and setters
@Repository("pacienteRepository")
public interface PacienteJpaRepository extends JpaRepository<Paciente, Serializable> {

    @Query("SELECT nombre FROM paciente WHERE rut_num= :rut_num")
    Future<String> findByRut(@Param("rut_num") int rut_num);
}
public interface PacienteService {

    public abstract Paciente findByRut(int rut_num);
}

@Service("pacienteServiceImpl")
public class PacienteServiceImpl implements PacienteService {

    @Autowired
    @Qualifier("pacienteRepository")
    private PacienteJpaRepository pacienteRepository;

    @Override
    public Paciente findByRut(int rut_num) {
        return (Paciente) pacienteRepository.findByRut(rut_num);
    }

}
@Controller
public class PacienteController {

    @Autowired
    @Qualifier("pacienteServiceImpl")
    private PacienteService pacienteService;

    @RequestMapping(value = "/paciente/{rut_num}", method = RequestMethod.GET, headers = "Accept=application/json")
    public ResponseEntity<Paciente> findByRut(@PathVariable("rut_num") int rut_num){
        Paciente paciente = pacienteService.findByRut(rut_num);
        if (paciente == null) {
            return new ResponseEntity(HttpStatus.NOT_FOUND);
            // You many decide to return HttpStatus.NOT_FOUND
        }
        return new ResponseEntity<Paciente>(paciente, HttpStatus.OK);
    }
}

控制台错误:

创建名为“Paciente ServiceImpl”的bean时出错:通过字段“Paciente Repository”表示的依赖项不满足;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“Paciente Repository”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:对方法public abstract java.util.concurrent.future com.calendar.repository.PacientEjparePository.findByRut(int)的查询验证失败!

共有1个答案

阴阳
2023-03-14

我认为问题是您在查询中重新检索到的实体的名称是“Paciente”而不是“Paciente”,因此更改

@Query("SELECT nombre FROM paciente WHERE rut_num= :rut_num")
Future<String> findByRut(@Param("rut_num") int rut_num);

@Query("SELECT nombre FROM Paciente WHERE rut_num= :rut_num")
Future<String> findByRut(@Param("rut_num") int rut_num);

应该工作

 类似资料:
  • 问题内容: 我想实现的想法是一个ID表。基本上,它具有以下结构(user_id,teacher_id),其中user_id是指我的User表中的主键,而讲者ID是指我的讲师表中的主键。 我正在尝试在Redis中实现此功能,但是如果我将键设置为用户的主要ID,则当我尝试运行查询时,例如 获得讲师ID = 5的所有记录, 因为讲师不是键,但是我不会 值 能够在O(1)时间到达。 如何形成上面提到的id

  • 我想执行如下查询: 使用Spring的我应该使用这样的东西: 现在想象一下,我不想检查4列,而是检查10或20列,方法名会很长! 我在这个答案中看到,我可以使用在许多列中搜索相同的文本,但我希望每个列都有不同的文本值。 有什么方法可以缩短find方法并动态添加列(以及相应的值)吗? 谢谢

  • 我正在使用selenium Java搜索不同的网站,我知道要查找特定的WebElement,有不同的方法,比如使用Xpath、使用Class或使用id。假设某网站具有如下所示的html结构 现在,如果我想从类名为“score”和“score_title”的div中提取文本,即1%的强度、43:1的情感、75%的激情和12%的到达,下面哪个选项最好。

  • 问题内容: 我想通过查找数据。我知道该数据存在并且存在(我已经用pymongo测试了它)。 但是下面的代码找不到它: 它只是给我一个回报。 但是我可以使用pytmongo和python找到它。 结果如下: 有人有什么主意吗? 编辑:我已经尝试了: 但我仍然有0: 问题答案: 您可以使用然后仅传递id值,或者使用,然后还必须使用字段名称指定一个值: 如果没有错误,则表示找到了文档。 如果您始终看到已

  • 问题内容: 我正在尝试查找具有Attribute的元素。好吧,我可以在Selenium中找到具有Id,tagName,Xpath和所有其他预定义方法的元素。但是,我正在尝试编写一种方法,该方法将给定属性名称和值作为输入专门返回WebElement。 假设XPath不是一个选择,还有其他更好的方法吗? 问题答案: 您可以使用CSS轻松完成此任务。 公式为: 所以如果有的话 您可以使用以下方法找到它:

  • 我正在尝试查找具有属性的元素。我可以在Selenium中找到Id、tagName、Xpath和所有其他预定义方法的元素。但是,我正在尝试编写一个方法,专门返回WebElement,给定属性名和值作为输入。 假设XPath不是一个选项,还有其他更好的方法吗?