package priv.mvc.handler;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
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.springframework.web.servlet.ModelAndView;
import priv.mvc.entity.Person;
//@SessionAttributes(value="person_mm") //如果要在request中存放student4对象,则同时将该对象 放入session域中
//@SessionAttributes(types= {Person.class,Address.class}) //如果要在request中存放Person类型的对象,则同时将该类型对象 放入session域中
@Controller
public class SpringMVC_Handler {
@RequestMapping("welcome")
public String welcome() {
return "sucess" ;
}
@RequestMapping(value="handler/transer" , method=RequestMethod.POST)
public String postHandler() {
return "sucess";
}
@RequestMapping(value="judge/handler" ,
method=RequestMethod.POST, params= {"name=zs","age!=23","address"})
public String judgeHandler() {
return "sucess";
}
@RequestMapping(value="*/handler" )
public String antHandler_01() {
return "sucess";
}
@RequestMapping(value="ant/**/handler" )
public String antHandler_02() {
return "sucess";
}
@RequestMapping(value="ant?/handler" )
public String antHandler_03() {
return "sucess";
}
@RequestMapping("handler/testRest/{id}")
public String testRest(@PathVariable("id") Integer id) {
System.out.println("id_post_add "+id);
return "sucess" ;
}
@RequestMapping("handler/testRest_delete/{id}")
public String testRest_delete(@PathVariable("id") Integer id) {
System.out.println(" _postToDel_delete "+id);
return "sucess" ;
}
//handler/testRest_update --- REST 风格更新
@RequestMapping("handler/testRest_update/{id}")
public String testRest_update(@PathVariable("id") Integer id) {
System.out.println(" _postToUPDATE_id "+id);
return "sucess";
}
//handler/rest_query/0004 --- REST 风格查询 方法名同增加方式,使用method= RequestMethod.GET区分
@RequestMapping(value="handler/testRest/{id}" ,method= RequestMethod.GET)
public String testRest_get(@PathVariable("id") Integer id) {
System.out.println("rest_query :" +id);
return "sucess";
}
//handler/transPara ---普通方式传递参数 代替 request.getParameter("uname")
@RequestMapping(value="handler/transPara",method= RequestMethod.GET)
public String transParaGet(@RequestParam("uname") String uname,@RequestParam(value="uage",required=false ,defaultValue="100") String uage) {
System.out.println("transPara-- : "+uname+"---"+uage);
return "sucess";
}
//handler/pojo"
@RequestMapping(value="handler/pojo")
public String pojoAccept( Person person) {
String infor = person.toString();
System.out.println("infor: "+infor);
return "sucess";
}
//handler/ModelAndView"
@RequestMapping(value="handler/MV")
public ModelAndView getModelAndView ( Person person) {
ModelAndView mv = new ModelAndView( "sucess");
mv.addObject("person_ModelAndView",person) ;
return mv;
}
// handler/modelMap
@RequestMapping(value="handler/modelMap")
public String testModelMap(ModelMap mm ,Person person_mm ) {
mm.put("person_mm", person_mm);//request域
return "sucess"; //view
}
@RequestMapping(value="handler/Map")
public String testMap(Map<String,Object> m,Person person_map) {
//request域
m.put("person_map", person_map);
return "sucess";
}
@RequestMapping(value="handler/convert") //
public String convertTest( @RequestParam("convertInfor") Person person) {
System.out.println(person.getId()+"-*-"+person.getName());
return "sucess";
}
@RequestMapping(value="handler/formmat") // 数据格式化
public String testFormmat( Person person) {
System.out.println(person.getId()+"-*-"+person.getName()+"-*-"+person.getBirthday());
return "sucess";
}
@RequestMapping(value = "handler/fileUpload")
public String testFileUpload(@RequestParam("desc") String desc , @RequestParam("file") MultipartFile file) throws Exception {
System.out.println("前端文件传输表单 描述信息 :"+ desc);
//transport file
InputStream inputFile = file.getInputStream() ;
String fileName = file.getOriginalFilename() ;
OutputStream outputFile = new FileOutputStream("F:\\JavaTrain\\targetFlie\\"+fileName);
int len = -1 ;
byte[] bs = new byte[1024] ;
while((len=inputFile.read(bs)) !=-1){
outputFile.write(bs, 0, len);
}
outputFile.close() ;
inputFile.close() ;
System.out.println(" 上传完成! ");
return "sucess";
}
}
灰乌鸦乌卡
- 粉丝: 50
- 资源: 7
最新资源
- C语言-leetcode题解之28-implement-strstr.c
- C语言-leetcode题解之27-remove-element.c
- C语言-leetcode题解之26-remove-duplicates-from-sorted-array.c
- C语言-leetcode题解之24-swap-nodes-in-pairs.c
- C语言-leetcode题解之22-generate-parentheses.c
- C语言-leetcode题解之21-merge-two-sorted-lists.c
- java-leetcode题解之Online Stock Span.java
- java-leetcode题解之Online Majority Element In Subarray.java
- java-leetcode题解之Odd Even Jump.java
- 计算机毕业设计:python+爬虫+cnki网站爬
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0