You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
1.4 KiB

  1. package com.simple.controller;
  2. import java.beans.PropertyEditorSupport;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import com.simple.domain.po.MallUserInfo;
  7. import com.simple.shiro.UserSession;
  8. import org.apache.shiro.SecurityUtils;
  9. import org.springframework.web.bind.WebDataBinder;
  10. import org.springframework.web.bind.annotation.InitBinder;
  11. import org.springframework.web.bind.annotation.RestController;
  12. @RestController
  13. public class BaseController {
  14. @InitBinder
  15. public void InitBinder(WebDataBinder dataBinder) {
  16. dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
  17. public void setAsText(String value) {
  18. try {
  19. setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value));
  20. } catch(ParseException e) {
  21. try {
  22. setValue(new SimpleDateFormat("yyyy-MM-dd ").parse(value));
  23. } catch (ParseException e1) {
  24. setValue(null);
  25. }
  26. }
  27. }
  28. public String getAsText() {
  29. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) getValue());
  30. }
  31. });
  32. }
  33. public MallUserInfo getUser(){
  34. MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo);
  35. return user;
  36. }
  37. public String getTenantId(){
  38. MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo);
  39. return user.getTenantId();
  40. }
  41. }