@Controller
@RequestMapping("/router")
@SessionAttributes(value = { "username" })
public class RouterController {
@RequestMapping(value = "/index", params = { "username", "age!=18" })
public String index() {
return "index";
} // 通配符的使用
@RequestMapping(value = "/testantpath/*/abc")
public String testantpath() {
return "index";
} // pathVariable
@RequestMapping(value = "/testpathvariable/{userId}")
public String testpathvariable(
@PathVariable(value = "userId") Integer userId) {
System.out.println(userId);
return "index";
} // RESTFUL
@RequestMapping(value = "/user/{userId}", method = RequestMethod.GET)
public String testgetmethod(@PathVariable(value = "userId") Integer userId) {
System.out.println("GET:" + userId);
return "index";
} @RequestMapping(value = "/user/{userId}", method = RequestMethod.POST)
public String testPostmethod(@PathVariable(value = "userId") Integer userId) {
System.out.println("POST:" + userId);
return "index";
} @RequestMapping(value = "/user/{userId}", method = RequestMethod.PUT)
public String testputmethod(@PathVariable(value = "userId") Integer userId) {
System.out.println("PUT:" + userId);
return "index";
} @RequestMapping(value = "/user/{userId}", method = RequestMethod.DELETE)
public String testdeletemethod(
@PathVariable(value = "userId") Integer userId) {
System.out.println("DELETE:" + userId);
return "index";
} // @RequestParam
@RequestMapping(value = "/tesrequestparam")
public String tesrequestparam(
@RequestParam(value = "username", required = false) String username) {
System.out.println(username);
return "index";
} // @RequestHeader
@RequestMapping(value = "/testrequestheader")
public String testrequestheader(
@RequestHeader(value = "Accept-Language") String al) {
System.out.println(al);
return "index";
} // @CookieValue
@RequestMapping(value = "/testcookievalue")
public String testcookievalue(
@CookieValue(value = "JSESSIONID") String cookie) {
System.out.println(cookie);
return "index";
} /*
* pojo的 获取
*/
@RequestMapping(value = "/testuser")
public String testpojo(TUser user) {
System.out.println(user);
// 数据库的操作
return "index";
} /*
* ModelAndView
*/
@RequestMapping(value = "/testmodelandview")
public ModelAndView testmodelandview() {
ModelAndView modelAndView = new ModelAndView("index");
modelAndView.addObject("username", "lisi");
return modelAndView;
} /*
* Map
*/
@RequestMapping(value = "/testmap")
public String testmap(Map<String, Object> map) {
map.put("age", 18);
return "index";
} /*
* Model
*/
@RequestMapping(value = "/testmodel")
public String testModel(Model model) {
model.addAttribute("email", "1@1.com");
return "index";
} /*
* @SessionAttributes
*/
@RequestMapping(value = "/testsession")
public String testsession(Model model) {
model.addAttribute("username", "wangwu");
return "index";
} /*
* @ModelAttribute
*/
@ModelAttribute
public void model(
@RequestParam(value = "userId", required = false) Integer userId,
Model model) {
if (userId != null) {
// 从数据库获取对象
TUser user = new TUser(userId, "wangwu", "123456", "1@1.com", 18);
model.addAttribute("user", user);
}
} @RequestMapping(value = "/testmodelattribute")
public String testmodelattribute(@ModelAttribute(value = "user") TUser user) {
System.out.println(user);
// 数据库的操作
return "index";
} /*
* 获取JSON数据
*/
@ResponseBody
@RequestMapping(value = "/testjson")
public TUser testjson() {
TUser user = new TUser(5, "wangwu", "123456", "1@1.com", 18);
return user; } /*
* 文件上传
*/
@RequestMapping(value = "/testupload")
public void upload(@RequestParam(name = "file1") MultipartFile file) {
File newFile = new File("E:\\" + file.getOriginalFilename());
if (!newFile.exists()) {
newFile.mkdirs();
}
try {
file.transferTo(newFile);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} /*
* servlet api
*/
@RequestMapping(value = "/testhttpservletrequest")
public String testHttpServletRequest(HttpServletRequest request) {
request.setAttribute("username", "admin");
return "index";
} /*
* redirect
*/
@RequestMapping(value = "/testredirect")
public String testRedirect() {
return "redirect:/router/testhttpservletrequest";
} /*
* testValidator
*/
@RequestMapping(value = "/testvalidator")
public String testValidator(@Valid TUser user, BindingResult result,
HttpServletRequest request) {
if (result.hasErrors()) {
List<FieldError> fieldErrors = result.getFieldErrors();
for (FieldError fieldError : fieldErrors) {
request.setAttribute("_error" + fieldError.getField(),
fieldError.getDefaultMessage());
}
}
return "index";
} }

controller大全(推荐)的更多相关文章

  1. JavaScript数组方法大全(推荐)

    原网址:http://www.jb51.net/article/87930.htm 数组在笔试中经常会出现的面试题,javascript中的数组与其他语言中的数组有些不同,为了方便之后数组的方法学习, ...

  2. JS鼠标事件大全 推荐收藏

    一般事件 事件 浏览器支持 描述 onClick HTML: 2 | 3 | 3.2 | 4 Browser: IE3 | N2 | O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 onDb ...

  3. Redis高级命令操作大全--推荐

    redis安装和使用 redis安装 wget http://download.redis.io/redis-stable.tar.gz tar zxvf redis-stable.tar.gz cd ...

  4. SharePoint 入门书籍推荐 转载来源http://www.cnblogs.com/jianyus/p/3513238.html

    最近,总有人说刚入门SharePoint,没有好的资料或者电子书,资料推荐大家多看看博客园和CSDN的博客.对于看博客,我一般是两个思路,要么找一个人的从头到尾看一遍,觉得有意义的,就把地址加收藏:或 ...

  5. SharePoint 入门书籍推荐

    最近,总有人说刚入门SharePoint,没有好的资料或者电子书,资料推荐大家多看看博客园和CSDN的博客.对于看博客,我一般是两个思路,要么找一个人的从头到尾看一遍,觉得有意义的,就把地址加收藏:或 ...

  6. 开发必备linux命令大全-稳赚不亏

    我们的服务一般都是在linux系统运行,因此了解一些关于linux命令是必须.接下来将一一详细介绍一些常用的linux的命令 文件操作 远程登录与操作 磁盘挂载 进程管理 启动和结束 系统性能参数查看 ...

  7. fir.im Weekly - 2016 开年技术干货分享

    开年上班,北上广的技术er 陆续重返"人间".看到别人已返工写代码,竟然有种慌慌的感觉(ง •̀_•́)ง 勤奋好学如你,fir.im weekly 送上最新一波技术分享供你 &q ...

  8. emberjs学习二(ember-data和localstorage_adapter)

    emberjs学习二(ember-data和localstorage_adapter) 准备工作 首先我们加入ember-data和ember-localstorage-adapter两个依赖项,使用 ...

  9. mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理

    1.mvc5+ef6+Bootstrap 项目心得--创立之初 2.mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理 3.mvc5+ef6+Bootstrap 项目心得--WebG ...

随机推荐

  1. gcc数据结构对齐之:why.

    gcc 支持 aligned 和 packed 属性指定数据对齐,那么在了解对齐规则之前,需要解决第一个以为,我们为什么需要数据对齐?请看下图: 相信学过汇编的朋友都很熟悉这张图,这张图就是CPU与内 ...

  2. 函数进阶装B操作

    三元表达式 条件成立时的返回值 if 条件 else 条件不成立时的返回值 x = 10 y = 20 print(f"x if x > y else y: {x if x > ...

  3. 面试mysql表设计要注意啥

    面试官:讲讲mysql表设计要注意啥? 引言 大家应该知道烟哥最近要(tiao 咳咳咳),嗯,不可描述! 随手讲其中一部分知识,都是一些烟哥自己平时工作的总结以及经验.大家看完,其实能避开很多坑.而且 ...

  4. qt嵌入式html和本地c++通信方式

    前沿:我们在做qt项目的时候,通常会把某个html网页直接显示到应用程序中.比如绘图.直接把html形式的图标嵌入到应用程序中 但是我们需要把数据从后台c++端传到html端,实现显示.qt实现了相关 ...

  5. 运维nslookup语法

    nslookup 查询域名DNS信息的工具 补充说明 nslookup命令 是常用域名查询工具,就是查DNS信息用的命令. nslookup4有两种工作模式,即“交互模式”和“非交互模式”.在“交互模 ...

  6. numpy中的argsort()函数

    在阅读<机器学习实战>一书中,发现了一个比较函数是argsort() 猜测是在numpy中出现的,手动进行了测试 >>> import numpy as np >& ...

  7. PHP的htmlspecialchars、strip_tags、addslashes

    PHP的htmlspecialchars.strip_tags.addslashes是网页程序开发中常见的函数,今天就来详细讲述这些函数的用法: 1.函数strip_tags:去掉 HTML 及 PH ...

  8. 关于&联系我

    本文已迁移至: Github博客:https://coco5666.github.io/blog/about Gitee博客:https://coco56.gitee.io/blog/about 博客 ...

  9. install - 复制文件并设置属性

    SYNOPSIS[总览] install [options] [-s] [--strip] source dest install [options] [-s] [--strip] source... ...

  10. windows 快捷键相关命令

    Mstsc  远程链接 Taskmgr 任务管理器 Regedit  打开注册表 Netstat -ano | find  “80” 查找内容 tasklist /fi "pid eq 57 ...