0

Ich habe bestätigt, dass ich die RedirectAttributes mit einem BusinessAuth Objekt mit nicht leeren Zeichenfolgen packen. Was mache ich falsch?Spring MVC - Flash-Attribute nicht angezeigt in Thymeleaf

Admincontroller:

@RequestMapping(path = BASE_URI + "/auth/business") 
public String generateBusinessKeys(RedirectAttributes redirectAttributes) { 
    String keyBusiness = ControllerUtil.getNewAuthKey(); 
    String keyMobile = ControllerUtil.getNewAuthKey(); 
    BusinessAuth auth = new BusinessAuth(keyBusiness, keyMobile); 
    businessAuthService.save(auth); 
    redirectAttributes.addFlashAttribute("businessAuth", auth); 

    return "/admin/home"; 
} 

HTML:

<p th:if="${businessAuth} != null" th:text="admin: "></p> 
<p th:if="${businessAuth} != null" th:text="${businessAuth.keyAdmin}"></p> <br /> 
<p th:if="${businessAuth} != null" th:text="mobile: "></p> <br /> 
<p th:if="${businessAuth} != null" th:text="${businessAuth.keyMobile}"></p> <br /> 

BusinessAuth:

@Entity 
public class BusinessAuth extends BaseEntity { 

private String keyMobile; 
private String keyAdmin; 

public BusinessAuth() {} 

public BusinessAuth(String keyMobile, String keyAdmin) { 
    this.keyMobile = keyMobile; 
    this.keyAdmin = keyAdmin; 
} 

public String getKeyMobile() { 
    return keyMobile; 
} 

public String getKeyAdmin() { 
    return keyAdmin; 
} 

}

+0

Flash-Attribute sind nach einer Weiterleitung zu verwenden, Sie leiten jedoch nicht nur Weiterleitungen weiter. Daher werden die Variablen niemals dem Modell hinzugefügt. Stattdessen fügen Sie sie einfach dem Modell oder der Umleitung hinzu. –

Antwort

0

Das Festlegen des Attributs auf einem ModelMap hat den Trick gemacht.

Verwandte Themen