我有两个通过数据库和登录名连接的java / spring-boot应用程序。在一个应用程序中,它是一个信息数据库。然后,我使用第二个应用程序仅向每个登录用户共享相关信息。 我想向登录的用户显示存储在“市场准入” sql表中的运营商列表。我有显示的列表,但需要获取每个运营商的图像。图像通过另一个包含信息的应用程序上传。然后,上载的图像位于服务器上的目录上载文件夹中: directory.for.carrier.appointment.files = C:\ Tomcat \ mysite.com \ carrier-files \ 并将图像文件名保存在“文档” sql表中。 我在访问图像时遇到问题。我不确定路径是否错误,或者访问文档存储的方式是否错误。
运行调试器时,可以在marketAccess方法中看到所需的信息。问题是文档返回为null且未在html中呈现图像。这是因为我在forEach循环中设置了模块属性吗?
是否有更好的方法来访问document.storage?
我的代码在下面,有关如何修复的任何建议将不胜感激。
@RequestMapping(value="/marketAccess")
public String marketAccess(Model model, @ModelAttribute("loggedUser")ResourceWebsiteUser user, CarrierAppointment carrierAppointment){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
user=userRepository.findByEmail(auth.getName());
user.getClient().getId();
List<MarketAccess> marketAccesses = marketAccessRepository.findByClient(user.getClient());
for(MarketAccess ma: marketAccesses) {
carrierAppointment= ma.getCarrierAppointment();
List<Document> docs= documentRepository.findByCarrierAppointment(carrierAppointment);
for (Document doc : docs) {
if (doc.getType() == "Logo") {
model.addAttribute("doc", doc);
}
}
}
model.addAttribute("marketAccesses", marketAccesses);
model.addAttribute("loggedUser",user);
return "marketAccess";
}
<div class="row">
<th:block th:each="ma: ${marketAccesses}">
<div class="col s6 m3 scale-transition scale-out">
<div class="white black-text valign-wrapper cacard" style="justify-content: center;">
<img th:if="${doc!=null}" th:src="/carrier-files/+${ma.carrierAppointment.parentCompanyCarrier+'-'+ma.carrierAppointment+'/'+doc.storage}"/>
<a target="_blank" th:href="${ma.carrierAppointment.quotingWebsite}"> <span class="center-align" style="width:100%; padding:10px;" th:text="${ma.carrierAppointment.parentCompanyCarrier}">
</span></a>
</div>
</div>
</th:block>
</div>
Document.java
@Entity
@Table(name="Document")
public class Document{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "DocumentId")
private Long id;
private String storage;
private String type;
@ManyToOne
@JoinColumn(name = "Client")
private Client client;
@ManyToOne
@JoinColumn(name = "CarrierAppointment")
private CarrierAppointment carrierAppointment;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStorage() {
return storage;
}
public void setStorage(String storage) {
this.storage = storage;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public CarrierAppointment getCarrierAppointment() {
return carrierAppointment;
}
public void setCarrierAppointment(CarrierAppointment carrierAppointment) {
this.carrierAppointment = carrierAppointment;
}
}
CarrierAppt.java
@Entity
@Table(name="CarrierAppointment")
@EntityListeners(AuditingEntityListener.class)
public class CarrierAppointment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CarrierAppointmentId")
private Long id;
private String parentCompanyCarrier;
private String linesOfBusiness;
private String quotingWebsite;
private String appetite;
private String knownForPersonal;
private String knownForCommercial;
public Long getId() {
return id;
}
public String getParentCompanyCarrier() {
return parentCompanyCarrier;
}
public String getLinesOfBusiness() {
return linesOfBusiness;
}
public String getQuotingWebsite() {
return quotingWebsite;
}
public String getAppetite() {
return appetite;
}
public String getKnownForPersonal() {
return knownForPersonal;
}
public void setKnownForPersonal(String knownForPersonal) {
this.knownForPersonal = knownForPersonal;
}
public String getKnownForCommercial() {
return knownForCommercial;
}
public void setKnownForCommercial(String knownForCommercial) {
this.knownForCommercial = knownForCommercial;
}
}
MarketAccess.java
@Entity
@Table(name="MarketAccess")
public class MarketAccess {
@Override
public String toString(){
return carrierAppointment.getParentCompanyCarrier();
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MarketAccessId")
private Long id;
@ManyToOne
@JoinColumn(name="client")
private Client client;
@ManyToOne
@JoinColumn(name = "carrier")
private CarrierAppointment carrierAppointment;
private String interest;
private Boolean commercialLines;
private Boolean personalLines;
private String username;
private String password;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public CarrierAppointment getCarrierAppointment() {
return carrierAppointment;
}
public void setCarrierAppointment(CarrierAppointment carrierAppointment) {
this.carrierAppointment = carrierAppointment;
}
public String getInterest() {
return interest;
}
public void setInterest(String interest) {
this.interest = interest;
}
public Boolean getCommercialLines() {
return commercialLines;
}
public void setCommercialLines(Boolean commercialLines) {
this.commercialLines = commercialLines;
}
public Boolean getPersonalLines() {
return personalLines;
}
public void setPersonalLines(Boolean personalLines) {
this.personalLines = personalLines;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}