您当前的位置: 首页 >  spring

星夜孤帆

暂无认证

  • 1浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringMVC基础-10-类型转换器

星夜孤帆 发布时间:2019-04-21 21:51:13 ,浏览量:1

pom.xml

  4.0.0
  com.monkey1024
  02mvc
  0.0.1-SNAPSHOT
  war
  
        
            junit
            junit
            3.8.1
            test
        
        
            javax.servlet
            javax.servlet-api
            3.1.0
        
        
            org.springframework
            spring-webmvc
            5.0.4.RELEASE
        

    
    
    	
        02mvc
        
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    
                    1.8
                    1.8
                    UTF-8
                
            
        
    
web.xml


	 
	
	
	
		characterEncodingFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
		
			
			encoding
			utf-8
		
		
		
		
			forceEncoding
			true
		
		
	
	
		characterEncodingFilter
		/*
	
	
	
		springMVC
		
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			classpath:springmvc.xml
		
		1
	
	
		springMVC
		/
	
springmvc.xml


        
	
	
	

	

	
	
	
	
	
	
	



	
	
	
	
	
	
	
		
			
				
				error/myerror
			
		
		
		
		
		
		
	
	
	
	
	
    
	
	
	
	
	
	
	
	
	
		
	
	
	
	
		
		
	
	

	
	

 
User.java
package com.monkey1024.bean;

import java.time.LocalDate;

import org.springframework.format.annotation.DateTimeFormat;

public class User {
	private String name;
	private int age;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private LocalDate birthday;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public LocalDate getBirthday() {
		return birthday;
	}
	public void setBirthday(LocalDate birthday) {
		this.birthday = birthday;
	}
}
UserController.java
package com.monkey1024.controller;

import java.time.LocalDate;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.monkey1024.bean.User;

@Controller
@RequestMapping("/user")
public class UserContoller {
	
	@RequestMapping("/addUser.do")
//	public ModelAndView addUser(String name, int age, @DateTimeFormat(pattern="yyyy-MM-dd") Date birthday) throws Exception{
//	public ModelAndView addUser(String name, int age, @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate birthday) throws Exception{
	public ModelAndView addUser(User user) throws Exception{
		ModelAndView mv = new ModelAndView();
		mv.addObject("name",user.getName());
		mv.addObject("age",user.getAge());
		mv.addObject("birthday",user.getBirthday());
		mv.setViewName("user");
		return mv;
	}

}
add_user.jsp




Insert title here


	
		姓名:
		年龄:
		生日:
		
	

 
user.jsp




Insert title here


	
		姓名:
		年龄:
		生日:
		
	

 

 

关注
打赏
1636984416
查看更多评论
立即登录/注册

微信扫码登录

0.0391s