gpt4 book ai didi

java - AJAX 响应与 java/hibernate 返回的字符串不同

转载 作者:行者123 更新时间:2023-12-01 10:01:40 26 4
gpt4 key购买 nike

我对这个简单的服务器端方法(java/hibernate)有一些问题:

@RequestMapping(value="/Prova" ,  method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ResponseEntity<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{

log.error("Sono qui");
return new ResponseEntity<String>("pippotopolinopaperino",HttpStatus.OK);

}

如果客户端发出 AJAX 请求(我使用 ExtJs),则响应为:

pippotopolinopa0015↵

为什么?

P.抱歉我的英语不好

P.p.s我也尝试过:

@RequestMapping(value="/Prova" ,  method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody String Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{

log.error("Sono qui");
return "pippotopolinopaperino";

}

最佳答案

我是这样解决的:

@RequestMapping(value="/Prova" ,  method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody List<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
List<String> ret = new ArrayList<String>();
ret.add("pippoPlutoTopolino");
return ret;
}

或者也:

@RequestMapping(value="/Prova2" ,  method=RequestMethod.POST)
@ResponseBody public StringBuffer Prova2(
HttpServletRequest request
) throws Exception
{
return new StringBuffer("pippoPlutoTopolino");
}

但我不明白为什么返回一个简单的字符串不起作用。

关于java - AJAX 响应与 java/hibernate 返回的字符串不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36774396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com