Serving Web使用Spring MVC
来源:互联网 发布:开淘宝店的账怎么做账 编辑:程序博客网 时间:2024/06/05 03:28
在spring构建web网站的方法中,HTTP请求被控制器处理。你通过@Controller注解,可以很容易的识别
request请求。
import java.util.concurrent.atomic.AtomicLong;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); @RequestMapping("/greeting") public @ResponseBody Greeting greeting( @RequestParam(value="name", required=false, defaultValue="World") String name, Model model) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); }@RequestMapping注解保证了HTTP请求/greeting和greeting()方法映射。注意,上面的例子没有确定是GET,或PUT,或POST请求,因为@RequestMapping
默认的匹配所有的http请求。@RequestParam
绑定了查询的字符串参数“name”的值到greeting()方法中的参数name。这个字符串参数不是必需的,如果request请求中没有那个值,那么它的默认值为“World”.name参数的值被添加到Model对象
上,最后可以访问到视图模板。
0 0
- Serving Web使用Spring MVC
- Serving Web Content with Spring MVC
- Serving Web Content with Spring MVC
- 【Java.Spring.MVC】使用Spring MVC构建Web应用程序
- Spring Web MVC使用技巧一则
- spring web mvc环境下使用dwr
- 使用Spring MVC进行web开发
- 使用Spring MVC构建Web应用程序
- 使用Spring MVC构建Web应用程序
- Docker使用TensorFlow Serving
- spring boot serving 静态网页
- spring web mvc资料
- spring web mvc配置
- Spring Web MVC
- Spring Web MVC入门
- SPRING WEB MVC 注解
- Spring Web MVC
- Spring mvc web.xml
- 关于java多线程的一些粗俗的理解
- warning: directory not found for option ' '
- UVa 100 The 3n + 1 problem
- 微信公众平台开发之砸金蛋
- 关于linux nand 驱动调试的一些注意点
- Serving Web使用Spring MVC
- cin作为while循环的条件
- axure 原型设计软件下载地址
- 题目1192:回文字符串
- 面向对象的*开闭原则*
- 七款Debug工具推荐:iOS开发必备的调试利器
- MapReduce,组合式,迭代式,链式
- 本博客现在开通了
- ubuntu 下TrueType EULA问题解决方案