我有两个实体:
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
); String userName
(它有字段School
); 在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> {
}
查询方法名称向数据库发出请求。例如,我想在学校中找到名为JPA
且John
的所有用户。
我如何通过id = 1
?
我唯一想到的是SchoolRepository
,但它给了我一个例外,即findByIdAndUsersUserName
表中没有名为users
的字段。
注:
当然,可以通过schools
进行,但我想知道是否可以通过@Query
进行此操作。