java void的返回值_SpringMVC中的返回值问题之一返回void

返回值为void

此方法需要引入一个json依赖

com.alibaba

fastjson

1.2.28

web.xml文件

/p>

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd" >

Archetype Created Web Application

CharactorEncoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceEncoding

true

CharactorEncoding

/*

springmvc

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc06Annotion.xml

1

springmvc

/

public class Student {

private String name;

private Integer age;

public String getName() {return name;}

public void setName(String name) {

this.name = name;

}

public Integer getAge() {

return age;

}

public void setAge(Integer age) {

this.age = age;

}

}

@Controller

public class ThridAnnotion {

/**

* 返回void json

* @param response

* @throws IOException

*/

@RequestMapping("/json")

public void Jack(HttpServletResponse response) throws IOException {

List list=new ArrayList();

Student student=new Student();

student.setName("李四");

student.setAge(20);

Student student1=new Student();

student1.setName("张三");

student1.setAge(22);

list.add(student);

list.add(student1);

String json = JSON.toJSONString(list);

//将json转发到浏览器

response.getWriter().write(json);

}

}

89b8eec18e68422a267e787133f59b65.png

springmvc06Annotion.xml文件

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

">

访问方式:

b739ec46bb5c46d9c0aa4ce35ba1ea56.png

关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。

本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。

[SpringMVC中的返回值问题之一返回void]http://www.zyiz.net/tech/detail-131302.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值