今日学习总计

/ /user/{id}

    @RequestMapping(value="/{id}",method=RequestMethod.GET)  

    public @ResponseBody User getUserInJson(@PathVariable String id,Map<String, Object> model){  

        int userId = Integer.parseInt(id);  

        System.out.println("userId:"+userId);

        User user = this.userService.getUserById(userId);  

        log.info(user.toString());

        return user;  

    }  

    

    // /user/{id}

    @RequestMapping(value="/jsontype/{id}",method=RequestMethod.GET)  

    public ResponseEntity<User>  getUserInJson2(@PathVariable String id,Map<String, Object> model){  

        int userId = Integer.parseInt(id);  

        System.out.println("userId:"+userId);

        User user = this.userService.getUserById(userId);  

        log.info(user.toString());

        return new ResponseEntity<User>(user,HttpStatus.OK);  

    } 

    

    //文件上传、

    @RequestMapping(value="/upload")

    public String showUploadPage(){

        return "user_admin/file";

    }

    

    @RequestMapping(value="/doUpload",method=RequestMethod.POST)

    public String doUploadFile(@RequestParam("file")MultipartFile file) throws IOException{

        if (!file.isEmpty()) {

            log.info("Process file:{}",file.getOriginalFilename());

        }

        FileUtils.copyInputStreamToFile(file.getInputStream(), new File("E:\\",System.currentTimeMillis()+file.getOriginalFilename()));

        return "succes";

    }

}  

 

 

3.4.6、新建jsp页面

file.jsp

 

复制代码

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Insert title here</title>

</head>

<body>

    <h1>上传文件</h1>

    <form method="post" action="/user/doUpload" enctype="multipart/form-data">

        <input type="file" name="file"/>

        <input type="submit" value="上传文件"/>

        

    </form>

</body>

</html>

 

posted @ 2021-11-20 23:29  禁小呆  阅读(17)  评论(0)    收藏  举报