spring MVC層處理方式的彙總

@Component
@RequestMapping("jsp/test")
public class TestSpring {
    protected final Logger log = LoggerFactory.getLogger(getClass());
    @RequestMapping(params = "method=getjson")
    @ResponseBody
    public String test1(){
        EaiBrand brand =new EaiBrand();
        brand.setBrandCode("brandCode");
        brand.setBrandName("brandName");
        brand.setEaiBrandId(12L);
        brand.setFailCount(2);
        return JSON.toJSONString(brand);
    }
    @RequestMapping(params = "method=getjson2")
    @ResponseBody
    public EaiBrand test2(){
        EaiBrand brand =new EaiBrand();
        brand.setBrandCode("brandCode");
        brand.setBrandName("brandName");
        brand.setEaiBrandId(12L);
        brand.setFailCount(2);
        return brand;
    }
    /**
     * 
     * restful風格測試. <br/> 
     * 
     * @author haibing.xiao
     * @date: 2015年4月24日 下午3:57:43
     * @version 1.0
     *
     * @param ownerId
     * @return
     */
    @RequestMapping(value="/{ownerId}")
    @ResponseBody
    public EaiBrand test3(@PathVariable String ownerId){
        log.info("ownerId={}",ownerId);
        EaiBrand brand =new EaiBrand();
        brand.setBrandCode("brandCode");
        brand.setBrandName("brandName");
        brand.setEaiBrandId(12L);
        brand.setFailCount(2);
        brand.setBrandName(ownerId);
        return brand;
    }
   

}


spring-mvc.xml配置

 <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
              
                <property name="supportedMediaTypes">
      <list>
       <!--返回字符串格式json-->
       <value>application/json;charset=UTF-8</value>
      </list>
     </property>
            </bean>
            
        </mvc:message-converters>
    </mvc:annotation-driven>

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章