Spring-Data JPA查询连接实体的方法名称

时间:2018-04-12 09:34:06

标签: java spring spring-data-jpa crud

我有两个实体:

  1. import 'rc-slider/assets/index.css'; import 'rc-tooltip/assets/bootstrap.css'; import React from 'react'; import ReactDOM from 'react-dom'; import Tooltip from 'rc-tooltip'; import Slider from 'rc-slider'; const createSliderWithTooltip = Slider.createSliderWithTooltip; const Range = createSliderWithTooltip(Slider.Range); const Handle = Slider.Handle; const handle = (props) => { const { value, dragging, index, ...restProps } = props; return ( <Tooltip prefixCls="rc-slider-tooltip" overlay={value} visible={dragging} placement="top" key={index} > <Handle value={value} {...restProps} /> </Tooltip> ); }; const wrapperStyle = { width: 400, margin: 50,padding:20 }; class Rangeslider extends React.Component { constructor(props) { super(props); this.state = { min: 0, max: 5000, }; } render(){ return( <div> <div> <div style={wrapperStyle}> <p>Range with custom handle</p> <Range min={0} max={5000} defaultValue={[0, 5000]} tipFormatter={value => `${value}`} /> <span>${this.state.min}</span> <span style={{float:"right"}}>${this.state.max}</span> </div> </div> </div> ) } } export default Rangeslider(它有字段User);
  2. String userName(它有字段School);
  3. Long id我有:

    School

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = User.class) @JoinColumn(name = "schoolId") private List<User> users; 我有:

    User

    我也有@ManyToOne(optional = false, targetEntity = School.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "schoolId", referencedColumnName = "id", nullable = false) private School school;

    SchoolRepository

    我想通过public interface SchoolRepositoryextends CrudRepository<School, Long> { } 查询方法名称向数据库发出请求。例如,我想在学校中找到名为JPAJohn的所有用户。 我如何通过id = 1

    执行此操作

    我唯一想到的是SchoolRepository,但它给了我一个例外,即findByIdAndUsersUserName表中没有名为users的字段。

    注:

    当然,可以通过schools进行,但我想知道是否可以通过@Query进行此操作。

0 个答案:

没有答案