首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >当我使用@ManyToMany时如何得到另一个类的值

当我使用@ManyToMany时如何得到另一个类的值
EN

Stack Overflow用户
提问于 2021-05-19 01:41:28
回答 2查看 55关注 0票数 0

我有两个班。请求和服务类。

请求类。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import com.eziz.clients.Clients;
import com.eziz.services.Services;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "request")
public class Requests {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long requestId;

    @Column(nullable = false, length = 80)
    private String requestComment;

    @Column(nullable = false, length = 15)
    private String requestStatus;

    @DateTimeFormat(pattern = "dd-MM-yyyy")
    @Column(nullable = false)
    private String requestExpiryTime;

    @DateTimeFormat(pattern = "dd-MM-yyyy")
    @Column(nullable = false)
    private String requestDateCreated;

    @ManyToOne
    @JoinColumn(name = "requestClientId")
    private Clients client;

    @ManyToMany
    @JoinColumn(name = "requestServiceId")
    private Set<Services> service = new HashSet<>();

//    @ManyToOne
//    @JoinColumn(name = "requestService")
//    private Services services;
//
    public Long getRequestId() {
        return requestId;
    }

    public void setRequestId(Long requestId) {
        this.requestId = requestId;
    }

    public String getRequestComment() {
        return requestComment;
    }

    public void setRequestComment(String requestComment) {
        this.requestComment = requestComment;
    }

    public String getRequestStatus() {
        return requestStatus;
    }

    public void setRequestStatus(String requestStatus) {
        this.requestStatus = requestStatus;
    }

    public String getRequestExpiryTime() {
        return requestExpiryTime;
    }

    public void setRequestExpiryTime(String requestExpiryTime) {
        this.requestExpiryTime = requestExpiryTime;
    }

    public String getRequestDateCreated() {
        return requestDateCreated;
    }

    public void setRequestDateCreated(String requestDateCreated) {
        this.requestDateCreated = requestDateCreated;
    }

    public Clients getClient() {
        return client;
    }

    public void setClient(Clients client) {
        this.client = client;
    }

    public Set<Services> getService() {
        return service;
    }

    public void setService(Set<Services> service) {
        this.service = service;
    }
}

服务班。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.eziz.services;


import javax.persistence.*;

@Entity
@Table(name = "service")
public class Services {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long serviceId;

    @Column(nullable = false, length = 20)
    private String serviceName;

    @Column(nullable = false, length = 30)
    private String serviceCategory;

    @Column(nullable = false)
    private double servicePrice;

    public Long getServiceId() {
        return serviceId;
    }

    public void setServiceId(Long serviceId) {
        this.serviceId = serviceId;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getServiceCategory() {
        return serviceCategory;
    }

    public void setServiceCategory(String serviceCategory) {
        this.serviceCategory = serviceCategory;
    }

    public double getServicePrice() {
        return servicePrice;
    }

    public void setServicePrice(double servicePrice) {
        this.servicePrice = servicePrice;
    }

    @Override
    public String toString() {
        return this.serviceName;
    }
}

现在,我在服务类中获得了serviceName和ManyToMany。但是我不能再得到其他的价值了,没有toString,我就需要这样做。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<div class="modal header">
    <h5 class="modal-title" id="modalTitle">Request Details</h5>
    <button aria-label="Close" class="close" data-dismiss="modal"
            type="button">
        <span aria-hidden="true">&times;</span>
    </button>
</div>

<div class="content content-fixed content-auth">
    <div class="container">
        <h1 class="tx-color-01 mg-b-5" align="center">
            SIFARIŞ MƏLUMATLARI </h1>
        <hr>
        <table class="table">
            <tr th:object="${request}">
            <tr>
                <th scope="col">Sifariş ID</th>
                <td scope="col" data-label="Sifariş ID" th:text="${request.requestId}"></td>
            </tr>
            <tr>
                <th scope="col">Qeydiyyat tarixi</th>
                <td data-label="Qeydiyyat tarixi" th:text="${request.requestDateCreated}"></td>
            </tr>
            <tr>
                <th scope="col">Xidmət</th>
                <td data-label="Xidmət" th:text="${request.service}"></td>
            </tr>
            <tr>
                <th scope="col">Təhvil vermə zamanı</th>
                <td data-label="Təhvil vermə zamanı" th:text="${request.requestExpiryTime}"></td>
            </tr>
            <tr>
                <th scope="col">Rəy</th>
                <td data-label="Rəy" th:text="${request.requestComment}"></td>
            </tr>
            <tr>
                <th scope="col">Status</th>
                <td data-label="Status" th:text="${request.requestStatus}"></td>
            </tr>
            </tr>
        </table>
    </div>
</div>


<div class="modal-footer">
    <button type="button" class="btn btn-danger" data-dismiss="modal">Bağla</button>
</div>

当我这样做的时候,我无法得到价值。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  <tr>
                <th scope="col">Xidmət</th>
                <td data-label="Xidmət" th:text="${request.service.serviceCategory}"></td>
            </tr>

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<tr>
                <th scope="col">Xidmət</th>
                <td data-label="Xidmət" th:text="${request.service.serviceCount}"></td>
            </tr>

我怎么能这么做?当我做request.service.serviceCount、serviceCategory或serviceName时,如何才能得到serviceName,因为我在这里编写toString方法返回this.serviceName。我可以使用toString方法获得所有这些信息。但我需要分开。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-05-19 23:23:12

这是我的Thymeleaf例子

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<p>
  <span th:each="task : ${foo.tasks}">
     <span th:text="${taskStat.index} + ': ' + ${task.name}"></span>
  </span>
</p> 



<tr th:each="book : ${listBooksTest}">
        <td th:text="${book.id}">ID Book</td>
        <td th:text="${book.id_author}">ID Author</td>
        <td th:text="${book.title}">Title</td>
        </td>
</tr>
票数 0
EN

Stack Overflow用户

发布于 2021-05-19 23:24:33

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   @GetMapping("/requests/view/{requestId}")
    public String requestDetails(@PathVariable(value = "requestId") long requestId, Model model) {

        Requests request = requestService.getRequestById(requestId);

        List<Clients> listClients = clientService.getAllClients();
        List<Services> listServices = serviceRepository.findAll();

        model.addAttribute("listServices", listServices);
        model.addAttribute("listClients", listClients);

        model.addAttribute("request", request);

        return "request_detail_modal";
    }

Yuxarıda list kimi gətirmişəm,onu burada td-əgətirmək lazımdı.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
            <tr>
                <th scope="col">Xidmət</th>
                <td data-label="Xidmət" th:field="*{service}" th:text="{}"></td>
            </tr>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67600745

复制
相关文章
Integer以及包装类使用值比较时需要注意的问题
这是因为Integer类源码中有一个IntegerCache,这一个私有的内部类。这个类缓存了-128到 127之间数字的包装类。需要记住它把一些数字的包装类提前缓存了,如果判断成立就把缓存中的那个包装类返回,如果不则new一个新的。
YanL
2020/04/29
1K0
Integer以及包装类使用值比较时需要注意的问题
当我们在谈免费游戏时
技术改变思想 本来不想用“当我们在谈XXX的时候,我们在谈什么”这种俗气的标题,但这个文章的内容,确实在一些人的想法里,还是有那么一点俗气的。所以用这个标题,也算文题对应吧。免费游戏,道具收费(Free To Play)作为一种游戏类型的存在,似乎是一个最近10年才开始的事情,但在中国,这种类型几乎成为了唯一的游戏类型。一切产品,都是因为有用户的市场需求才会存在,但是免费游戏这个市场,又是如何被挖掘出来的呢?——这对于看清楚免费游戏背后的用户需求,应该是有很多好处的。 2006年的某天,我的老板给我打了个
韩伟
2018/03/05
2.3K1
当我们在谈免费游戏时
Elasticsearch:如何在搜索时得到精确的总 hits 数
从 Elasticsearch 7.0之后,为了提高搜索的性能,在 hits 字段中返回的文档数有时不是最精确的数值。Elasticsearch 限制了最多的数值为10000。
腾讯云大数据
2020/10/29
7.6K0
Elasticsearch:如何在搜索时得到精确的总 hits 数
Python 如何正确调用 jar 包加密,得到加密值?
在做接口自动化的时候,经常会遇到一些参数是需要加密的,比如密码参数。 加密规则一般开发也不愿意告诉你,会直接给你一个jar包,让你调用jar包得到加密值,在jmeter上是可以直接引用jar包的,但python调用jar包会有点麻烦。
上海-悠悠
2021/08/20
1.1K0
Python 如何正确调用 jar 包加密,得到加密值?
当我们拿到数据进行建模时, 如何选择更合适的算法?
2.其次,看数据特征的数据类型,然后做一些初步的数据统计,比如是否数据均衡,大致的数据分布是怎样的(不同类别的分布)
公众号guangcity
2019/09/20
1K0
当我们拿到数据进行建模时,  如何选择更合适的算法?
使用Matlab划分系统聚类树,得到不同的类的聚类分析。
1、点击[命令行窗口] 2、按<Enter>键 3、点击[命令行窗口] 4、按<Enter>键 5、点击[命令行窗口] 6、按<Enter>键
裴来凡
2022/05/28
5270
使用Matlab划分系统聚类树,得到不同的类的聚类分析。
go: 当我们在使用sync.Map时,发生了什么
sync.Map是我比较喜欢的一个库,用了非常久,今天突发奇想瞧瞧它的实现。又一次被宇宙中第二NB的语言--go 折服了。 这里准备写一篇文章,讨论下当使用sync.Map执行操作的时候,会发生什么。
超级大猪
2020/07/06
9700
当我开始使用React 时,我希望我知道这些知识
自2013年5月29日首次发布以来,React.js已经占领了互联网。我和许多其他开发人员将他们的成功归功于这个了不起的框架,这已经不是什么秘密了。
前端小智@大迁世界
2019/06/15
9380
当我们谈注册中心时谈什么?
注册中心对于服务提供者需要具备服务注册、注销的能力,对于服务消费者需要提供查询服务、感知服务变化的功能。当然还需要解决一些其他问题才能成为一个优秀的注册中心,如高可用、高性能、水平扩展能力、服务探活能力、路由功能、多机房(多活)能力等。
龟仙老人
2020/12/16
6020
当我学python时遇见的问题汇总(持续更新)
PS:一开始我在cmd里面安装过pygame的,但是我用IDLE运行时还是出错,于是只能自己去网上下载来安装
天天Lotay
2022/12/01
5520
当我学python时遇见的问题汇总(持续更新)
当我们谈论内容时,我们在谈什么?
作为数字音乐界『双App』之一的虾米音乐迎来了一个爆款内容:《我的少女时代》主题曲《小幸运》在虾米音乐播放量超过三千万,这首由田馥甄演唱的歌,在数字音乐平台的表现很是亮眼,虾米音乐则凭这一爆款内容在用户获取等方面收获满满。过去一个平台可以成就一个明星、一首歌曲,现在反过来,一首单曲竟然具有如此大的魔力,给平台带来助力。这一现象本质是,移动互联网进入内容时代,而《小幸运》的成功给内容产业还是带来了些许启发的。 内容究竟是什么鬼? 2015年可谓中国内容创业的大年,音乐、视频、广播、文学、动漫诸多数字内容领域都
罗超频道
2018/04/28
9330
当我们谈部署时,我们在谈什么?
计算机网络把各地的计算机连接了起来,只要有一台可以上网的终端,比如手机、电脑,就可以访问互联网上任何一台服务器的资源(包括静态资源和动态的服务)。
神说要有光zxg
2022/04/12
6180
当我们谈部署时,我们在谈什么?
如何遍历一个实例的所有属性,得到属性的名称和值
College college = this.collegeService.getCollegeById(id); try { Field[] fields = college.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true);//类中的成员变量为private,须进行此操作 System.out.pri
qubianzhong
2018/09/19
2.6K0
当我谈论URL编码时我在谈论什么
今天收到一个 Bug, 一个超级奇怪的人名叫做 Isxxxxa Onxxxna Anton
szhshp
2022/08/15
2830
当我做 hackathon 时我在做什么 (3)
治大国若烹小鲜。做 hackathon 也是如此:需要有合适的方法(能),合适的工具(贤),然后朝着目标方向不疾不徐,缓步前进(有所为有所不为)。
tyrchen
2021/01/29
6960
当我做 hackathon 时我在做什么 (3)
当我做 hackathon 时我在做什么 (1)
从上周四开始的周末(1/7-1/10),是 Tubi 一年一度的 OSS-a-thon。所谓 OSS-a-thon,是我们为了回馈开源社区举办的 hackathon,参与者需要做和开源项目有关的项目 — 可以是对已有的开源项目进行改进,提交 PR,或者做新的项目,但需要开源。
tyrchen
2021/01/29
1.1K0
当我做 hackathon 时我在做什么 (1)
Flex反射得到属性和属性的值
       今天要写一个生成json的方法,目的是将VO对象中的所有公共属性和值转换成一个json对象,这个类中20多个属性,手动拼的话,是个体力活,并且有其它的对象也要转成json,还要手动拼,脑袋里最先想到的就是反射。
高爽
2022/05/07
1.7K0
如何使用枚举的组合值
有时我们需要将枚举定义为1,2,4,8.......的值,这样当传入一个3,那么就是表示1,2的组合,如果传入7,那就表示1,2,4的组合。要实现这种功能我们需要用到FlagsAttribute。具体用法如下:
深蓝studyzy
2022/06/16
3K0
当我们在谈零信任时,我们谈的是什么?
ZERO TRUST在2010年由Forrester分析师John Kindervag正式提出。
腾讯安全
2021/08/13
5460
当我们在谈零信任时,我们谈的是什么?
点击加载更多

相似问题

Django DetailView得到ManyToMany关系的值

12

当我拥有@ManyToMany时如何设置ForeignKey名称

31

有时,当我使用FCM时,我会得到空值。

11

当我使用Jest时,如何得到工作承诺?

21

当我使用withCookies()时得到警告

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文