【问题标题】:(SPRING) get user's information from postgresql database and print in thymeleaf html(SPRING) 从 postgresql 数据库中获取用户信息并在 thymeleaf html 中打印
【发布时间】:2018-02-22 20:31:36
【问题描述】:

我目前正在使用 SPRING,我想将用户的详细信息从数据库(我正在使用 postgresql)打印到 HTML 页面(基于百里香的模板),有什么方法可以从我的 Controller 类中做到这一点,以及如何在 HTML Thymeleaf 页面上打印?

这是我的代码的详细信息:

控制器类,

package com.owlexa.cms.web.controller;
// ...
import com.owlexa.cms.dto.UsersDto;
import com.owlexa.cms.model.Role;
import com.owlexa.cms.model.Users;
import com.owlexa.cms.search.UserSearchParams;
import com.owlexa.cms.service.UserService;

@Controller
@RequestMapping("/case")
@SessionAttributes("searchParamSession")
public class CaseController extends BaseController {

    Logger log = Logger.getLogger(this.getClass());

    @Autowired
    private MessageSource messageSource;

    @Autowired
    UserService userService;

    @PreAuthorize("hasAnyAuthority('" + ACLConstant.MENU_CASE_PAYMENT + "','" + ACLConstant.MENU_CASE_ACTIVECASE + "')")
    @RequestMapping(value = "/searchCase", method = {RequestMethod.GET, RequestMethod.POST})
    public String searchpayment(Model model, HttpServletRequest request) {
        return "case/searchCase";
    }
}

这是我的html页面

<tr>
  <td><label>Provider Name </label></td>
  <td><label>:</label></td>
  <td>
    <input type="text" value="**(GET USER FIRST NAME ?)**" style="width:275px;" readonly="readonly">
  </td>
</tr>

提前谢谢,如果您需要其他详细信息,我会更新它。

【问题讨论】:

    标签: java html spring postgresql thymeleaf


    【解决方案1】:

    假设您实现了UserDetails 接口并且该类具有firstName 之类的属性:

    <input type="text" data-th-value="${#request.userPrincipal.principal.firstName}">
    

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 2014-07-19
      • 2023-04-06
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多