首页 \ 问答 \ JPA 一对多关系

JPA 一对多关系

在一个项目中,我需要知道某个学生借阅的图书,在此基础上我还需要知道某个学生借阅的本专业的图书。因此,我想映射成两个成员变量。如何做? 对于所有图书: @OneToMany(mappedBy = "student") private List books;//所有图书列表 对于专业图书,有没有什么办法?
更新时间:2022-06-28 13:06

最满意答案

RecyclerView的2级嵌套
看到同一个滚动控件中出现了3种混合布局,多数人第一映像就是进行嵌套。 
如果进行嵌套的话,嵌套什么?从效果图来看,上图的一个栏目中的视图数量似乎是固定的,这意味着可以使用RelativeLayout等布局进行硬排版。确实如果真是固定的这样做当然更好,但是注意到点击每个栏目上的刷新按钮的时候,偶尔会出现两个视图交换位置的动画,这是RecyclerView特有的,而且也没有人告诉我每个栏目中的视图数量就是固定,万一哪天又多了一排呢,所以我们还是嵌套RecyclerView,具体嵌套规则如下图:

其实最外层的RecyclerView1换成ScrollView也可以,只要把内部的RecyclerView依次拼接起来就可以,实现起来也更加简单,实现方式千千万,自己选个喜欢的而已,我只是为了便于拓展,万一需要动态的增加栏目呢。
上一篇就说到了RecyclerView的嵌套的问题,给每个RecyclerView设置对应的Fully****LayoutManager就可以了。具体实现参见源码,我就不贴了,重新getItemViewType方法为每个position位置的item设置不同的type类型,然后在onCreateViewHolder创建对应的Holder,最后在onBindViewHolder为不同类型的item设置不同的Fully布局的子RecyclerView就行了。
@Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder1){
            holder.child_recyclerView.setLayoutManager(new FullyLinearLayoutManager(context));
        }else if (holder instanceof MyViewHolder2){
            holder.child_recyclerView.setLayoutManager(new FullyGridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false));
        }else if (holder instanceof MyViewHolder3){
            holder.child_recyclerView.setLayoutManager(new FullyGridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false));
        }else if (holder instanceof MyViewHolder4){
            holder.child_recyclerView.setLayoutManager(new FullyGridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false));
        }
    }

其他回答

看你列数固定否,我做过类似项目,简单的方法如下:
1、表格行、列固定的,你每个单元格当成一个textview,中间的表格线也是textview,你懂得。像最左侧的合并3行的单元格可以用线性布局为控制。
2、表格列数不定的,表头用textview做好固定的,下边放一个listview,listview的每一行用固定的格式,格式文件的写法同上。
明白吧,有不明白的我再补充。

相关问答

更多
  • 一、利用JVM提供的-Xmn -Xms -Xmx等选项可进行设置内存。 二、解决办法: 修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat Service Manager\Tomcat5\Parameters\JavaOptions 原值为-Dcatalina.home="C:\ApacheGroup\Tomcat 5.0"-Djava.endorsed.dirs="C:\ApacheGroup\Tomcat 5.0\comm ...
  • 打开360—系统修复—IE设置—解除锁定—修改主页—某主页 选好主页去〈什么主页自选〉—锁定—立即应用。
  • 你从那网站找的图片不支持外链 就是只能在那个网站显示 放在其他网站的就显示这个
  • 1、点击“开始”找“设置”到“控制面板”到“Internet选项”,找到更改主页,在地址栏里输入你喜欢的地址后点击“使用当前页”,然后再点击“确定”就OK了。 或者,直接打开你喜欢的网页,在网页的上方找到“设为首页”,点击一下就有了你想要的网页为主页了。
  • RecyclerView的2级嵌套 看到同一个滚动控件中出现了3种混合布局,多数人第一映像就是进行嵌套。 如果进行嵌套的话,嵌套什么?从效果图来看,上图的一个栏目中的视图数量似乎是固定的,这意味着可以使用RelativeLayout等布局进行硬排版。确实如果真是固定的这样做当然更好,但是注意到点击每个栏目上的刷新按钮的时候,偶尔会出现两个视图交换位置的动画,这是RecyclerView特有的,而且也没有人告诉我每个栏目中的视图数量就是固定,万一哪天又多了一排呢,所以我们还是嵌套RecyclerView,具体 ...
  • 当然,永远不会失败。 在发布上述问题解决方案大约一分钟后,可能遇到了同样的问题: ContextWrapper.getFilesDir() 在这里找到 Of course, never fails. Found the solution about a minute after posting the above question... solution for those that may have had the same issue: ContextWrapper.getFilesDir() Fo ...
  • 这种活动称为启动画面。 您可以查看此相关问题以了解如何执行此操作。 This kind of Activity is called a Splash Screen. You can check this related question to find out how to do it.
  • 是的,你正在寻找的是所谓的滑动抽屉 Yes what you are looking for is called Sliding Drawer
  • 您可以使用另一种方式来处理您的家庭ImageButton点击这样 ImageButton ivHome = (ImageButton) toolbar.findViewById(R.id.home); ivHome.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log("TAG","Home ...
  • 我希望更改代码以在库存主屏幕上显示一个图标,以便在选择该选项时,可以选择在主样本和TouchWiz之间进行选择。 我假设“股票主屏幕”你的意思是“样本主屏幕”。 在这种情况下,“库存主屏幕”是一个Activity 。 您可以像在任何其他Android活动中一样向“库存主屏幕”添加“图标”,例如通过修改res/layout/home.xml布局文件以包含ImageButton 。 I am looking to alter the code to have an icon available on the s ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)