在Spring boot 项目中 利用@ResponseBody返回JSON数据
在项目中碰到了一个问题
现在有一个实体类。
public class TestEntity {
private String html;
private String other;
public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
public String getOther() {
return other;
}
public void setOther(String otherl) {
this.other = other;
}
@Override
public String toString() {
return "TestEntity [html=" + html + ", other =" + other + "]";
}
}
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/test")
public TestEntity test(){
TestEntity testEntity = new TestEntity();
//实际数据从数据库中回去,数据保存整个HTML
testEntity.setHtml("<div id=\"0001\"></div>");
testEntity.setOther("id=123456789");
return testEntity;
}
}
利用测试工具postman获取到的数据
{"html":"id=\"123456\"","other":"id=123456789"}
前端正真需要的数据形式是{"html":"<div id="0001"></div>","other":"id=123456789"}