gistfile1.txt package org.tlgg.control;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;import org.
package org.tlgg.control;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.tlgg.bean.Roles;
import org.tlgg.bean.UserInfo;
@Controller
public class NewController {
@ModelAttribute("userinfo")//用于把返回值保存到Model中为属性
public UserInfo getInfo(){
return new UserInfo(101,"tl","ss",12, null, "男");
}
@RequestMapping(value="/newDemo",method=RequestMethod.GET)
public String newDemo(){
System.out.println("/index-get");
return "newDemo";
}
@RequestMapping(value="/newDemo",method=RequestMethod.POST)
public String newDemo(@ModelAttribute("userinfo")UserInfo info,@RequestParam("file")MultipartFile file,HttpServletRequest request) throws IllegalStateException, IOException{
//生成独一无二的img名称
String img = request.getSession().getId()+System.currentTimeMillis();
file.transferTo(new File("f://"+img+".txt"));
System.out.println("/index-post"+info);
return "newDemo";
}
@ModelAttribute("list")
public List
initList(){
List
list=new ArrayList
(); list.add(new Roles(1, "BOSS")); list.add(new Roles(2, "HR")); list.add(new Roles(3, "CEO")); list.add(new Roles(4, "CF0")); return list; } } --------------------------------------
text/html;charset=UTF-8
---------------------------------------- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
Insert title here
用户名:
密码:
男
女
上传个人文件:
spring
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:/AnotationAOP.xml
1
spring
/
