標籤:oaf bean rtp 代碼 eoq mvm lan exp sep
剛學習了ssm架構,ajax校正成功,分享下
1.匯入jar包
2.配置spring-servlet.xml
1 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 2 <property name="messageConverters"> 3 <list> 4 <ref bean="mappingJackson2HttpMessageConverter" /> 5 </list> 6 </property> 7 </bean> 8 <bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 9 <property name="supportedMediaTypes"> 10 <list> 11 <value>text/html;charset=UTF-8</value> 12 <value>text/json;charset=UTF-8</value> 13 <value>application/json;charset=UTF-8</value> 14 </list> 15 </property> 16 </bean>
3.控制器中用@ResponseBody實現返回json資料格式
1 @ResponseBody2 @RequestMapping(value="queryByUser", method=RequestMethod.POST,produces="application/json;charset=UTF-8") 3 public User queryByName(User user,HttpServletRequest request){4 User u = userBiz.queryByName(user);5 return u;6 }
4.頁面中接收查詢到的結果
function checkUser(){ var username=$("#username").val(); $.ajax({ url:"queryByUser", type:"post", data:{"username":username}, dataType:"json", success:function(data){ if (data!=null ) { $("#userSpan").text("使用者名稱已存在"); $("#username").val(‘‘); }else if(data==null && username !=‘‘){ $("#userSpan").text("使用者名稱可用"); } } }); }
實現結果就是以下這樣的:
SSM整合架構實現ajax校正