标签:conf find private 设置 oca lan cep pat image
1 <!-- 解决post乱码问题 --> 2 <filter> 3 <filter-name>encoding</filter-name> 4 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 5 <!-- 设置编码参是UTF8 --> 6 <init-param> 7 <param-name>encoding</param-name> 8 <param-value>UTF-8</param-value> 9 </init-param> 10 </filter> 11 <filter-mapping> 12 <filter-name>encoding</filter-name> 13 <url-pattern>/*</url-pattern> 14 </filter-mapping> 15 16 <servlet> 17 <servlet-name>dispathcherServlet</servlet-name> 18 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 19 <init-param> 20 <param-name>contextConfigLocation</param-name> 21 <param-value>classpath:springmvc.xml</param-value> 22 </init-param> 23 </servlet> 24 25 <servlet-mapping> 26 <servlet-name>dispathcherServlet</servlet-name> 27 <url-pattern>*.action</url-pattern> 28 </servlet-mapping>
29 </web-app>
1
// web-->input.String --> bean.Date
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven> 2 3 <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> 4 <property name="converters"> 5 <set> 6 <bean class="com.xing.convert.DataConvert"></bean> 7 </set> 8 </property> 9 </bean>
package com.xing.convert; import org.springframework.core.convert.converter.Converter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DataConvert implements Converter<String, Date> { @Override public Date convert(String s) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { return format.parse(s); } catch (ParseException e) { e.printStackTrace(); } return null; } }
private Date birthday;
1 @Autowired 2 @Qualifier("accountService") 3 private AccountService accountService; 4 5 @RequestMapping("all.action") 6 public ModelAndView all(){ 7 List<Account> all = accountService.findAll(); 8 ModelAndView modelAndView = new ModelAndView(); 9 modelAndView.addObject("accounts",all); 10 modelAndView.setViewName("all.jsp"); 11 return modelAndView; 12 } 13 14 @ResponseBody 15 @RequestMapping("findById.action") 16 public String findById(Integer id){ 17 return accountService.findById(id).toString(); 18 } 19 20 @ResponseBody 21 @RequestMapping("add.action") 22 public String add(Account account){ 23 Integer add = accountService.add(account); 24 return add>0?"OK":"Sorry,Fail of Insert"; 25 } 26 27 @ResponseBody 28 @RequestMapping("showTime.action") // 这里是String --> Date 自动封装 29 public String showTime(Account account){ 30 return account.toString(); 31 }
1 <%@page pageEncoding="UTF-8" %> 2 <html> 3 <body> 4 5 <form action="showTime.action" method="get"> 6 <input type="text" name="name" placeholder="input your name..."> 7 <input type="text" name="birthday" placeholder="input your birthday...such as : 2000-01-01"> 8 <input type="submit" value="insert"> 9 </form> 10 </body> 11 </html>
未完...
标签:conf find private 设置 oca lan cep pat image
原文地址:https://www.cnblogs.com/xxing/p/11865315.html