thymeleaf显示特定的用户个人资料

时间:2016-05-06 12:07:03

标签: spring-boot thymeleaf user-profile

我很喜欢百里香和春季靴子,所以我不知道我在寻找什么来解决我的问题。 我的网站列表中显示了几个用户。当我点击其中一个用户时,我想显示用户个人资料页面。

列表如下所示:

<ul>
    <li th:each="section : ${sections}">
        <a href="overviewDivision.html?id=1" th:href="@{/overviewDivision?id=1}">
            <span th:text="${section.name}">Bereich3</span>
        </a>
        <ul>
            <li th:each="person : ${personSectionService.getPersonsBySectionId(section.id)}">
                <a href="overviewEmployee.html?id= + person.id" th:href="@{/overviewEmployee?id= + person.id}">
                    <span th:text="${person.firstName + ' ' + person.lastName}">
                    </span>
               </a>
           </li>
       </ul>
   </li>
</ul>

这是我的控制者:

@RequestMapping(value = "/overviewEmployee", method = RequestMethod.GET)
public String overviewEmployee(Model model) {
    model.addAttribute("sections", sectionService.getAllSections());
    model.addAttribute("personSectionService", personSectionService);
    model.addAttribute("currentPerson", personService.getById(1));
    return "overviewEmployee";
}

在个人资料页面上,我使用currentPerson.firstName等来获取有关用户的信息。 所以我的问题是,如何将currentPerson更改为列表中最后点击的人?或者我完全错了吗?

1 个答案:

答案 0 :(得分:1)

您需要有2个处理程序:一个用于显示列表,另一个用于获取详细信息。前者不应在模型中设置description,因为您还没有此信息。

你的处理程序应该是这样的:

currentPerson

(注意使用@RequestMapping(value = "/employees", method = RequestMethod.GET) public String overviewEmployee(Model model) { model.addAttribute("sections", sectionService.getAllSections()); model.addAttribute("personSectionService", personSectionService); return "employee-list"; } @RequestMapping(value = "/overviewEmployee", method = RequestMethod.GET) public String overviewEmployee(Model model, @RequestParameter long id) { model.addAttribute("currentPerson", personService.getById(id)); return "overviewEmployee"; }

我假设您的@RequestParameterid,并且这是强制性的。