[英]How to build customise repository in springboot for microservices
how to design your own customise repository in Java springboot for micro services Get Api which will take one or n number of parameter define in request object如何在 Java 中为微服务设计自己的自定义存储库
For eg: search/user?will give all user details search/user?name=john will give data only have name with have john Search/user?name=john&salary=100 will give specific data to name and salary search/user?name=john&salary=100&add=china will give specific record to name salary and address例如: search/user? 将给出所有用户详细信息 search/user?name=john 将给出数据只有 name 和 have john Search/user?name=john&salary=100 将给出特定数据到 name 和薪水 search/user?name =john&salary=100&add=china 会给出具体记录姓名工资和地址
Same way the this one Url search/user will take one or n number of define request object in it so that this single Api will give output json objects as per the inputs provided Same way the this one Url search/user will take one or n number of define request object in it so that this single Api will give output json objects as per the inputs provided
below is my code and the error i am getting in joining a query下面是我的代码和我在加入查询时遇到的错误
Mobile Entity:移动实体:
@Entity
@Table(name = "MOBILE")
public class Mobile implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Mobile.class);
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "brand")
private String brand;
@Column(name = "phone")
private String phone;
@Column(name = "picture")
private String picture;
@Column(name = "sim")
private String sim;
@Column(name = "resolution")
private String resolution;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name ="hardware_id",referencedColumnName = "id")
private Hardware hardware;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="releases_id",referencedColumnName = "id")
private Releases releases;
Hardware Entity硬件实体
@Entity
@Table(name="Hardware")
public class Hardware implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Hardware.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name="audioJacks")
private String audioJacks;
@Column(name = "gps")
private String gps;
@Column(name = "battery")
private String battery;
enter code here
Releases Entity class发布实体 class
enter code here
@Entity
@Table(name="Releases")
public class Releases implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Releases.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name="priceEuro")
private long priceEuro;
@Column(name="announceDate")
private String announceDate;
Repoimplementation重新实现
@Repository
@Transactional(readOnly = true)
public class UserRepositoryCustomizedImpl implements UserRepoCustom {
@PersistenceContext
EntityManager entityManager;
@Override
public List<UserInformation> search(Map<String, String> requestMap) {
if(requestMap!=null && requestMap.isEmpty()) {
}
//Below commented all the query i tried i got the error for all it is query which is wrong i am writing help me with the write query :)
//String qry="Select m.brand,m.phone,m.picture,h.audioJacks,h.gps from
com.example.users.m.hardware_id.Mobile m inner join
com.example.users.entities.Hardware h where m.hardware_id=h.id ";
//SELECT DISTINCT e FROM Employee e INNER JOIN e.tasks t
//String qry="select m from Mobile m inner join m.hardware h";
String qry="Select m.brand from Mobile m inner join m.hardware_id h
where h.id=m.hardware_id";
System.out.println("Query is "+ qry);
Query query = entityManager.createQuery(qry,Hardware.class);
return query.getResultList();
}
}
String qry="Select m.brand from Mobile m inner join m.hardware_id h where h.id=m.hardware_id"; String qry="Select m.brand from Mobile m inner join m.hardware_id h where h.id=m.hardware_id";
You are referring to hardware_id
as the join property (assuming it as the join column name)您将hardware_id
称为连接属性(假设它是连接列名称)
You should instead use the property name of the attribute in the Entity class.您应该改用实体 class 中的属性名称。 ie hardware
即hardware
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.