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

Manual Dalam Talian YMP / 高級(jí)特性—控制器請(qǐng)求處理器

高級(jí)特性—控制器請(qǐng)求處理器

在WebMVC模塊中除了支持標(biāo)準(zhǔn)Web請(qǐng)求的處理過程,同時(shí)也對(duì)基于XML和JSON協(xié)議格式的請(qǐng)求提供支持,有兩種使用場景:

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

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

ymp.configs.webmvc.request_processor_class=default

場景二:針對(duì)具體的控制器方法進(jìn)行設(shè)置;

@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ù)的驗(yàn)證等特性;