国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

YMP在線手冊 / 高級特性—控制器請求處理器

高級特性—控制器請求處理器

在WebMVC模塊中除了支持標準Web請求的處理過程,同時也對基于XML和JSON協(xié)議格式的請求提供支持,有兩種使用場景:

場景一:全局設置,將影響所有的控制器方法;

通過下面的參數(shù)配置,默認為default,可選值為[default|json|xml],也可以是開發(fā)者自定義的IRequestProcessor接口實現(xiàn)類名稱;

ymp.configs.webmvc.request_processor_class=default

場景二:針對具體的控制器方法進行設置;

@Controller
@RequestMapping("/demo")
public class DemoController {

    @RequestMapping("/sayHi")
    @RequestProcessor(JSONRequestProcessor.class)
    public IView sayHi(@RequestParam String name, @RequestParam String content) {
        return View.textView("Hi, " + name + ", Content: " + content);
    }

    @RequestMapping("/sayHello")
    @RequestProcessor(XMLRequestProcessor.class)
    public IView sayHello(@RequestParam String name, @RequestParam String content) {
        return View.textView("Hi, " + name + ", Content: " + content);
    }
}

通過POST方式向http://localhost:8080/demo/sayHi發(fā)送如下JSON數(shù)據(jù):

{ "name" : "YMPer", "content" : "Welcome!" }

通過POST方式向http://localhost:8080/demo/sayHello發(fā)送如下XML數(shù)據(jù):

<xml>
    <name>YMPer</name>
    <content><![CDATA[Welcome!]]></content>
</xml>

以上JSON和XML這兩種協(xié)議格式的控制器方法,同樣支持參數(shù)的驗證等特性;