2016-05-06 70 views
0

我是新的thymeleaf和春季启动,所以我真的不知道我在寻找什么来解决我的问题。 我有几个用户在我的网站列表中显示。当我点击其中一个用户时,我想显示用户个人资料页面。百里香显示特定的用户配置文件

名单如下:

<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

您需要有2个处理程序:一个显示您的列表,一个显示详细信息。前者不应在模型中设置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"; 
} 

(注意使用@RequestParameter

我假设你idlong,而且它是强制性的。