package com.baobaotao.web;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.management.RuntimeErrorException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;
import com.baobaotao.UserService;
import com.baobaotao.domain.Dept;
import com.baobaotao.domain.User;
@Controller
@RequestMapping("/user")
// @SessionAttributes(value={"user","user1","user2"},types={Dept.class})
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(method = RequestMethod.POST)
public ModelAndView createUser(User user) {
userService.createUser(user);
ModelAndView mav = new ModelAndView();
mav.setViewName("user/createSuccess");
mav.addObject("user", user);
return mav;
}
@RequestMapping(value = "/register", method = RequestMethod.GET, params = "!myParam")
public String register(@ModelAttribute("user") User user) {
return "user/register";
}
@RequestMapping(value = "/delete", method = RequestMethod.POST, params = "userId")
public String test1(@RequestParam("userId") String userId) {
// do sth
return "user/test1";
}
@RequestMapping(value = "/show", headers = "content-type=text/*")
public String test2(@RequestParam("userId") String userId) {
// do sth
return "user/test2";
}
// ①请求参数按名称匹配的方式绑定到方法入参中,方法返回对应的字符串代表逻辑视图名
@RequestMapping(value = "/handle1",method=RequestMethod.PUT)
public String handle1(@RequestParam("userName") String userName,
@RequestParam("password") String password,
@RequestParam("realName") String realName) {
return "success";
}
// ②将Cooke值及报文头属性绑定到入参中、方法返回ModelAndView
@RequestMapping(value = "/handle2")
public ModelAndView handle2(@CookieValue("JSESSIONID") String sessionId,
@RequestHeader("Accept-Language") String accpetLanguage) {
ModelAndView mav = new ModelAndView();
mav.setViewName("success");
mav.addObject("user", new User());
return mav;
}
// ③请求参数按名称匹配的方式绑定到user的属性中、方法返回对应的字符串代表逻辑视图名
@RequestMapping(value = "/handle3")
public String handle3(User user) {
return "success";
}
// ④直接将HTTP请求对象传递给处理方法、方法返回对应的字符串代表逻辑视图名
@RequestMapping(value = "/handle4")
public String handle4(HttpServletRequest request) {
return "success";
}
@RequestMapping(value = "/handle11")
public String handle11(
@RequestParam(value = "userName", required = false) String userName,
@RequestParam("age") int age) {
return "success";
}
@RequestMapping(value = "/handle12")
public String handle12(
@CookieValue(value = "sessionId", required = false) String sessionId,
@RequestParam("age") int age) {
return "success";
}
@RequestMapping(value = "/handle13")
public String handle13(@RequestHeader("Accept-Encoding") String encoding,
@RequestHeader("Keep-Alive") long keepAlive) {
return "success";
}
@RequestMapping(value = "/handle14")
public String handle14(User user) {
return "success";
}
@RequestMapping(value = "/handle21")
public void handle21(HttpServletRequest request,
HttpServletResponse response) {
String userName = request.getParameter("userName");
response.addCookie(new Cookie("userName", userName));
}
@RequestMapping(value = "/handle22")
public ModelAndView handle22(HttpServletRequest request) {
String userName = WebUtils.findParameterValue(request, "userName");
ModelAndView mav = new ModelAndView();
mav.setViewName("success");
mav.addObject("userName", userName);
return mav;
}
@RequestMapping(value = "/handle23")
public String handle23(HttpSession session) {
session.setAttribute("sessionId", 1234);
return "success";
}
@RequestMapping(value = "/success")
public String success() {
return "success";
}
@RequestMapping(value = "/fail")
public String fail() {
return "fail";
}
@RequestMapping(value = "/handle24")
public String handle24(HttpServletRequest request,
@RequestParam("userName") String userName) {
return "success";
}
@RequestMapping(value = "/handle25")
public String handle25(WebRequest request) {
String userName = request.getParameter("userName");
return "success";
}
@RequestMapping(value = "/handle31")
public void handle31(OutputStream os) throws IOException {
Resource res = new ClassPathResource("/image.jpg");
FileCopyUtils.copy(res.getInputStream(), os);
}
// @RequestMapping(value="/{userId}")
// public ModelAndView showDetail(@PathVariable("userId") String userId){
// ModelAndView mav = new ModelAndView();
// mav.setViewName("user/showDetail");
// mav.addObject("user", userService.getUserById(userId));
// return mav;
// }
@RequestMapping(value = "/handle41")
public String handle41(@RequestBody String body) {
System.out.println(body);
return "success";
}
@ResponseBody
@RequestMapping(value = "/handle42/{imageId}")
public byte[] handle42(@PathVariable("imageId") String imageId)
throws IOException {
System.out.println("load image of " + imageId);
Resource res = new ClassPathResource("/image.jpg");
byte[] fileData = FileCopyUtils.copyToByteArray(res.getInputStream());
return fileData;
}
@RequestMapping(value = "/handle43")
public String handle43(HttpEntity<String> requestEntity) {
long contentLen = requestEntity.getHeaders().getContentLength();
System.out.println("user:" + requestEntity.getBody());
return "success";
}
@RequestMapping(value = "/handle44/{imageId}")
public ResponseEntity<byte[]> handle44(
@PathVariable("imageId") String imageId) throws Throwable {
Resource res = new ClassPathResource("/image.jpg");
byte[] fileData = FileCopyUtils.copyToByte
没有合适的资源?快使用搜索试试~ 我知道了~
Spring MVC的教程项目代码
共141个文件
jar:40个
properties:28个
class:18个
4星 · 超过85%的资源 需积分: 9 163 下载量 8 浏览量
2012-02-12
13:24:54
上传
评论
收藏 24.27MB RAR 举报
温馨提示
奉上学习Spring MVC 3.0的技术资料PPT资料,我花了两天写成,该资料根据最新拙作的《Spring 3.x 企业应用开发实战 》写成,仅需要1个小时左右的时间,就可以让你学习到Spring MVC 3.0的所有知识点和新功能,强烈推荐下载学习,内容大致如下: Spring MVC框架简介 HTTP请求地址映射 HTTP请求数据的绑定 数据转换、格式化、校验 数据模型控制 视图及解析器 其它杂项内容
资源推荐
资源详情
资源评论
收起资源包目录
Spring MVC的教程项目代码 (141个子文件)
UserController.class 19KB
UserControllerTest.class 9KB
UserControllerTest.class 8KB
UserListPdfView.class 4KB
UserListExcelView.class 3KB
User.class 3KB
TestFreemarker.class 2KB
TestFreemarker.class 2KB
UserValidator.class 2KB
ResourcePathExposer.class 1KB
StringToUserConverter.class 1KB
Dept.class 1KB
UserEditor.class 1KB
UserService.class 1KB
MySimpleMappingExceptionResolver.class 1KB
MyBindingInitializer.class 922B
MyHandlerExceptionResolver.class 812B
Address.class 535B
userListFtl.ftl 530B
listUser.ftl 307B
listUser.ftl 307B
listUser.ftl 307B
bg.gif 206KB
spmvcPro.iml 12KB
spmvcPro.ipr 24KB
spmvcPro.iws 66KB
com.springsource.org.aspectj.tools-1.6.6.RELEASE.jar 8.43MB
poi-ooxml-schemas-3.7.jar 3.78MB
com.springsource.net.sf.jasperreports-2.0.5.jar 1.89MB
poi-3.7.jar 1.6MB
com.springsource.com.lowagie.text-2.0.8.jar 1.13MB
com.springsource.freemarker-2.3.15.jar 869KB
jackson-all-1.6.9.jar 849KB
com.springsource.org.castor-1.2.0.jar 848KB
org.springframework.context-3.0.5.RELEASE.jar 653KB
org.springframework.beans-3.0.5.RELEASE.jar 542KB
com.springsource.org.joda.time-1.6.0.jar 533KB
poi-ooxml-3.7.jar 487KB
com.springsource.com.thoughtworks.xstream-1.3.1.jar 428KB
org.springframework.web.servlet-3.0.5.RELEASE.jar 409KB
com.springsource.org.apache.taglibs.standard-1.1.2.jar 389KB
com.springsource.org.apache.velocity-1.5.0.jar 388KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
org.springframework.web-3.0.5.RELEASE.jar 386KB
com.springsource.javax.mail-1.4.0.jar 384KB
org.springframework.core-3.0.5.RELEASE.jar 373KB
iTextAsian.jar 322KB
com.springsource.org.hibernate.validator-4.1.0.GA.jar 281KB
com.springsource.org.junit-4.7.0.jar 231KB
com.springsource.org.apache.commons.beanutils-1.8.0.jar 228KB
com.springsource.org.apache.commons.lang-2.1.0.jar 205KB
org.springframework.test-3.0.5.RELEASE.jar 200KB
org.springframework.expression-3.0.5.RELEASE.jar 166KB
com.springsource.org.apache.commons.io-1.4.0.jar 108KB
org.springframework.context.support-3.0.5.RELEASE.jar 99KB
servlet-api.jar 86KB
jettison-1.3.jar 71KB
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
org.springframework.oxm-3.0.5.RELEASE.jar 60KB
com.springsource.org.apache.commons.fileupload-1.2.0.jar 53KB
org.springframework.asm-3.0.5.RELEASE.jar 52KB
com.springsource.javax.validation-1.0.0.GA.jar 48KB
slf4j-api-1.6.1.jar 25KB
com.springsource.javax.servlet.jsp.jstl-1.1.2.jar 21KB
slf4j-log4j12-1.6.1.jar 10KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
UserController.java 18KB
UserControllerTest.java 8KB
User.java 2KB
UserListPdfView.java 2KB
UserListExcelView.java 2KB
TestFreemarker.java 1KB
ResourcePathExposer.java 743B
UserValidator.java 742B
Dept.java 703B
MySimpleMappingExceptionResolver.java 620B
MyBindingInitializer.java 501B
UserService.java 478B
UserEditor.java 455B
StringToUserConverter.java 425B
MyHandlerExceptionResolver.java 421B
Address.java 190B
Snap2.jpg 88KB
Snap2.jpg 88KB
image.jpg 60KB
image.jpg 60KB
Snap1.jpg 37KB
Snap1.jpg 37KB
test.js 42B
register4.jsp 2KB
register3.jsp 2KB
register.jsp 1KB
register2.jsp 992B
index.jsp 834B
userList.jsp 774B
userListMix.jsp 774B
uploadPage.jsp 513B
themeTest.jsp 494B
test.jsp 398B
welcome.jsp 321B
共 141 条
- 1
- 2
hajunma
- 粉丝: 1
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页