我正在创建移动充电网站的管理页面使用spring引导和SQL作为后端。我创建了单独的表格,用于存储预付费、邮资和加载项的计划。现在我想把这三张表都整合起来。
也就是说,当我输入(/prepaid) URL时,它应该显示预付费表的数据,当我输入(/postpaid) URL时,它应该显示后置表的数据,就像加载项一样。我对整合一点都不了解。有谁能分享一些例子或给出一些想法吗?
代码的Github链接。这是预付费的春季启动代码。就像我做的一样,我做了邮资和附加。请参考代码并分享您的想法。
发布于 2022-03-26 06:32:27
它的工作方式也将与您处理Admin的方式相同。
注意事项:基本上每个表都需要模型,每个模型都需要存储库。
模型
@Table(name = "prepaid")
public class Prepaid implements Serializable{
/*all fields here*/
/*Getter and Setter*/
}
@Table(name = "postpaid")
public class Postpaid implements Serializable{
/*all fields here*/
/*Getter and Setter*/
}
@Table(name = "addon") //<--necessary in all model
public class Addons implements Serializable{
/*all fields here*/
/*Getter and Setter*/
}仓库
public interface PrepaidRepo extends JpaRepository<Prepaid,Long> {
/*all functions here*/
}
public interface PostpaidRepo extends JpaRepository<Postpaid,Long> {
/*all functions here*/
}
public interface AddonRepo extends JpaRepository<Addon,Long> {
/*all functions here*/
}服务
public class PostpaidService{
PostpaidRepo postpaid;
/*handling functions*/
}
public class PrepaidService{
PrepaidRepo prepaid;
/*handling functions*/
}
public class AddonService{
AddonRepo addon;
/*handling functions*/
}控制器
@RequestMapping("/prepaid-plan")
public class PrepaidController{
/*route handling functions*/
}
@RequestMapping("/postpaid-plan")
public class PostpaidController{
/*route handling functions*/
}
@RequestMapping("/addon-plan")
public class AddonController{
/*route handling functions*/
}https://stackoverflow.com/questions/71625706
复制相似问题