JSONの送信と受信(工事中)

``` java:Demo3Application
package com.example.demo;

// https://searchman.info/java_eclipse/1130.html
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Demo3Application {

	public static void main(String[] args) {
		SpringApplication.run(Demo3Application.class, args);
	}

}
```

``` java:HelloController
package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

	@RequestMapping(value="/hello")
	private String hello(){
		return "/index.html";
	}
}
```


``` java:MainController
package com.example.demo;
import java.util.ArrayList;
import java.util.List;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

// https://itsakura.com/java-springboot-json

@RestController
@RequestMapping("/test1")
public class MainController {

	@RequestMapping(value = "/index2", method = {RequestMethod.POST})
	@ResponseBody
	public List<Syain> output2(
			@RequestBody List<Syain> syain) {
				System.out.println(syain.get(1).getBangou());
				System.out.println(syain.get(1).getName());
				return syain;
	}
	
	@RequestMapping(value = "/index3/{id}", method = RequestMethod.GET, 
			consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public List<Syain> output3(@PathVariable("id") final long id) {
		List<Syain> out = new ArrayList<Syain>(5);
		out.add(new Syain("a", "A"));
		out.add(new Syain("b", "B"));
		
		return out;
	}
}
```

``` java:Syain 
package com.example.demo;
import java.io.Serializable;
import lombok.Data;

@Data
public class Syain implements Serializable {
	public Syain(String bangou, String name) {
		this.bangou = bangou;
		this.name = name;
	}
	private static final long serialVersionUID = 1L;
	
	private  String bangou;
	private  String name;
	
}
````

``` jsp:index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="p1"></p>
<p id="p2"></p>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#p1").text("");
$("#p2").text("");
var json1 = [
    {
        "bangou": "1",
        "name": "鈴木"
    },
    {
        "bangou": "2",
        "name": "田中"
    },
    {
        "bangou": "3",
        "name": "佐藤"
    }
];
$.ajax({	
	url:"http://localhost:8080/test1/index2",
	type:"POST",
	contentType: "application/json",
	data:JSON.stringify(json1),
	dataType:"json"
	}).done(function(data1,textStatus,jqXHR) {
		$("#p1").text(jqXHR.status);
		$("#p2").text(JSON.stringify(data1));
	}).fail(function(jqXHR, textStatus, errorThrown){
		$("#p1").text(jqXHR.status);
	}).always(function(){
	});
</script>
</html>
```

``` jsp:index2.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="p1"></p>
<p id="p2"></p>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#p1").text("");
$("#p2").text("");
var json1 = {
		  "bangou": "1",
		  "name": "鈴木"
		};
$.ajax({	
	url:"http://localhost:8080/test1/index3/123",
	type:"GET",
	contentType: "application/json",
	dataType:"json"
	}).done(function(data1,textStatus,jqXHR) {
		$("#p1").text(jqXHR.status); //例：200
		$("#p2").text(JSON.stringify(data1));
	}).fail(function(jqXHR, textStatus, errorThrown){
		$("#p1").text(jqXHR.status); //例：404
	}).always(function(){
	});
</script>
</html>
```