如何通过用户ID获取状态列表

时间:2019-03-21 06:48:37

标签: mysql spring-boot

我是学习者,我正在尝试通过userId获取状态列表,但是我仅获得状态表的第一条记录,我的错觉是什么可以帮助我,我尝试了很多,但我不理解我的错觉

控制器

List<StatesDTO>statesList = statesRepository.findByUserid(1);
System.out.println("States list---->"+Conversions.getGson().toJson(statesList));

存储库

public interface StatesRepository extends JpaRepository<StatesDTO, Integer>{
   List<StatesDTO>findByUserid(int id);
}

州DTO:

@Entity
@Table(name = "states")
public class StatesDTO {

    private int userid;
    private int stateid;
    private String statename;

    public int getUserid() {
        return userid;
    }
    public void setUserid(int userid) {
        this.userid = userid;
    }
    public int getStateid() {
        return stateid;
    }
    public void setStateid(int stateid) {
        this.stateid = stateid;
    }
    public String getStatename() {
        return statename;
    }
    public void setStatename(String statename) {
        this.statename = statename;
    }

}

表格

userid stateid statename
'4', '40', 'up'
'3', '10', 'ap'
'3', '30', 'tn'
'2', '30', 'tn'
'2', '40', 'up'
'1', '10', 'ap'
'1', '20', 'ts'

0 个答案:

没有答案