YMP ??? ???
/ 高級(jí)特性—控制器請(qǐng)求處理器
高級(jí)特性—控制器請(qǐng)求處理器
在WebMVC模塊中除了支持標(biāo)準(zhǔn)Web請(qǐng)求的處理過(guò)程,同時(shí)也對(duì)基于XML和JSON協(xié)議格式的請(qǐng)求提供支持,有兩種使用場(chǎng)景:
場(chǎng)景一:全局設(shè)置,將影響所有的控制器方法;
通過(guò)下面的參數(shù)配置,默認(rèn)為default,可選值為[default|json|xml],也可以是開(kāi)發(fā)者自定義的IRequestProcessor接口實(shí)現(xiàn)類名稱;
ymp.configs.webmvc.request_processor_class=default
場(chǎng)景二:針對(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); } }
通過(guò)POST方式向http://localhost:8080/demo/sayHi
發(fā)送如下JSON數(shù)據(jù):
{ "name" : "YMPer", "content" : "Welcome!" }
通過(guò)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)證等特性;