我正在开发Spring Boot Web API应用程序。我的应用程序正在返回json数据。 json响应中的属性之一是“ logMessages”,它返回一个xml字符串(保存在数据库中)。但是在浏览器上,xml响应返回带有转义符。我的控制器类如下
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.bbby.pdm.entities.PDMStepItemOutbound;
import com.bbby.pdm.repositories.PDMStepItemOutboundRepository;
@CrossOrigin(origins = "*", allowedHeaders = "*")
@Controller
@RequestMapping("stepoutbound")
public class PDMController {
@Autowired
private PDMStepItemOutboundRepository pDMStepItemOutboundRepository;
@RequestMapping(value = "/correlationid", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE }, headers = "Accept=application/json")
public ResponseEntity<?> getStepOutboundXmlByCorrelationId(@RequestParam String correlationid, Model model)
throws Exception {
List<PDMStepItemOutbound> dataList = pDMStepItemOutboundRepository.findByCorrelationId(correlationid);
return ResponseEntity.ok(dataList);
}
浏览器的响应片段:
[{
"transactionType":"Start-Audit",
"time_stamp":"2018-02-08 16:23:37.0070000",
"logMessages":"<STEP-ProductInformation xmlns=\"http://www.example.com/step\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.stibosystems.com/step PIM.xsd\" ExportTime=\"2018-02-08 15:51:47\" ExportContext=\"Context1\" ContextID=\"Context1\" WorkspaceID=\"Approved\" UseContextLocale=\"false\" AutoApprove=\"N\" AutoInitiate=\"N\" StateflowImportEvent=\"N\" STEPWorkflowImportEvent=\"N\" ExportTransactionID=\"-1\" ReplaceProductValues=\"N\" AllowInvalidValues=\"N\" ReplaceAttributeLinks=\"N\" ReplaceProductToProductCrossReferences=\"N\" ReplaceTerms=\"CLEAR_ONLY_FOR_IMPORTED_PRODUCTS\" ReplaceClassificationToClassificationCrossReferences=\"N\" ReplaceOverrideToSubProductReferences=\"N\" SingleUpdateMode=\"N\"
...等等。
如何避免这些转义字符?我也尝试在Web上找到解决方案,但是在搜索中,“ / json中的xml响应”关键字被视为XML响应。请帮助解决此问题,因为我需要显示数据库中的xml。显示带有转义符的xml不会提供清晰的视图。