博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Springmvc格式转换
阅读量:4228 次
发布时间:2019-05-26

本文共 1378 字,大约阅读时间需要 4 分钟。

创建一个Formatter类

public class USLocalDateFormatter implements Formatter
{ public static final String US_PATTERN="MM/dd/yyyy"; public static final String NORMAL_PATTERN="dd/MM/yyyy"; @Override public LocalDate parse(String s, Locale locale) throws ParseException { return LocalDate.parse(s,DateTimeFormatter.ofPattern(getPattern(locale))); } @Override public String print(LocalDate localDate, Locale locale) { return DateTimeFormatter.ofPattern(getPattern(locale)).format(localDate); } //根据地域不同,用户输入方式不同 public static String getPattern(Locale locale){ return isUnitedStates(locale)? US_PATTERN:NORMAL_PATTERN; } //判断是否在美国 private static boolean isUnitedStates(Locale locale){ return Locale.US.getCountry().equals(locale.getCountry()); }}
@Controllerpublic class ProfileController {    //注册一个bean,根据地理位置,确定不同格式,用于前端给用户提醒。    @ModelAttribute("dateFormat")    public String localeFormat(Locale locale){        return USLocalDateFormatter.getPattern(locale);    }    @RequestMapping("/profile")    public String displayProfile(){        return "profilePage";    }    @RequestMapping(value = "/profile",method= RequestMethod.POST)    public String saveProfile(@ModelAttribute("profileForm") ProfileForm profileForm){        System.out.println("save ok"+profileForm);        return "profilePage";    }}
配置:

转载地址:http://gojqi.baihongyu.com/

你可能感兴趣的文章
Microsoft Exchange Server 2003 Advanced Administration
查看>>
Performance Analysis of Communications Networks and Systems
查看>>
SQL Server CE Database Development with the .NET Compact Framework
查看>>
Service Design for Six Sigma: A Roadmap for Excellence
查看>>
Maximum Security (3rd Edition)
查看>>
Discovering Knowledge in Data: An Introduction to Data Mining
查看>>
Computer Applications in Pharmaceutical Research and Development
查看>>
Software Measurement and Estimation: A Practical Approach
查看>>
Microsoft SQL Server 2005 Express Edition For Dummies
查看>>
Excel Pivot Tables Recipe Book: A Problem-Solution Approach
查看>>
USB Mass Storage: Designing and Programming Devices and Embedded Hosts
查看>>
JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach
查看>>
From VBA to VSTO: Is Excel's New Engine Right for You?
查看>>
Sams Teach Yourself Data Structures and Algorithms in 24 Hours
查看>>
Professional Windows Desktop and Server Hardening
查看>>
Software Estimation: Demystifying the Black Art (Best Practices
查看>>
Handbook of Research on Mobile Multimedia
查看>>
SQLite (Developer's Library)
查看>>
Measuring Information Systems Delivery Quality
查看>>
Windows 2000 Performance Guide
查看>>