Today I see a code that returns a string in the controller of SPRINGMVC, which I call the 2b code (in English name: 2b).
@RequestMapping (value="twob.do") Public voidTwobcode (httpservletrequest request,httpservletresponse response) {//.......... n Rows omitted here Try{Response.setcontenttype ("Type=text/html;charset=utf-8"); String s="a bunch of strings ..."; Response.getwriter (). write (s); } Catch(Exception e) {e.printstacktrace (); } return;}
I do not understand, all with STRINGMVC. SPRINGMVC gives us such a powerful function, why do you return a string with a response object??
======================== Gorgeous split-line =======================
There are a lot of ways to SPRINGMVC return strings, a simple and rude way:
Using @responsebody annotations to return strings
@RequestMapping (value="getjosn.do", produces="text/html;charset=utf-8 "public String Gettabjson () { "{" No theme ":"http:///www.wuzhuti.cn "}"; return JSON;}
So far, have not encountered any abnormal demand, has been using this method.
If you write code when there is any abnormal demand, this method can not meet or have a problem, welcome to leave a message to discuss, I will promptly reply.
SPRINGMVC return string