HTTP 状态 500 - 意外令牌:,靠近第 1 行,第 129 列
Posted
技术标签:
【中文标题】HTTP 状态 500 - 意外令牌:,靠近第 1 行,第 129 列【英文标题】:HTTP Status 500 - unexpected token: , near line 1, column 129 【发布时间】:2019-12-09 03:51:27 【问题描述】:错误如下:
HTTP 状态 500 - 请求处理失败;嵌套异常是 org.hibernate.hql.internal.ast.QuerySyntaxException: 意外令牌:,靠近第 1 行,第 129 列 [从 invoicedetails i 中选择零件编号、零件描述、发票编号、数量,零件 p WHERE i.invoicenumber in :invoiceList,i。 partnumber = p.partNo AND 数量
我尝试运行查询并将记录保存在 xlx 文件中。但是当我执行它时返回错误意外令牌。我是否以正确的方式编写查询?
查询在 SQL 工作台上运行良好
你们能帮我解决这个问题吗?非常感谢您的帮助。谢谢
实体类
public class SpecialOrder
public String partdescription;
public Integer invoicenumber;
public String partnumber;
public Integer quantity;
public Integer year;
public SpecialOrder()
super();
public SpecialOrder(Integer invoicenumber, String partnumber, Integer quantity, Integer year,
String partdescription)
super();
this.invoicenumber = invoicenumber;
this.partnumber = partnumber;
this.quantity = quantity;
this.year = year;
this.partdescription = partdescription;
public String getPartdescription()
return partdescription;
public Integer getInvoicenumber()
return invoicenumber;
public String getPartnumber()
return partnumber;
public Integer getQuantity()
return quantity;
public Integer getYear()
return year;
public void setPartdescription(String partdescription)
this.partdescription = partdescription;
public void setInvoicenumber(Integer invoicenumber)
this.invoicenumber = invoicenumber;
public void setPartnumber(String partnumber)
this.partnumber = partnumber;
public void setQuantity(Integer quantity)
this.quantity = quantity;
public void setYear(Integer year)
this.year = year;
控制器类
@RequestMapping("specialorder")
public ModelAndView SpecialOrder(@RequestParam("invoiceno") String invoiceno, Model map, HttpSession session,
ModelAndView mav) throws ConnectException
AppUser user = (AppUser) session.getAttribute("user");
if (user == null)
throw new OrderNotFoundException();
else
List<Integer> invoiceNoList = new ArrayList();
if (invoiceno.contains(","))
String[] array = invoiceno.split(",");
for (String s : array)
invoiceNoList.add(Integer.parseInt(s));
else
invoiceNoList.add(Integer.parseInt(invoiceno));
List<SpecialOrder> invoiceList = ordersService.getSpecialOrder(invoiceNoList);
System.out.println("invoice list = " + invoiceList);
mav.clear();
mav.setView(new SpecialOrderExcelView());
// mav.setViewName("specialorderpage");
mav.addObject("user", user);
mav.addObject("branch", branch);
mav.addObject("appcss", appcss);
mav.addObject("sysdate", InsightUtils.getNewUSDate());
mav.addObject("invoiceList", invoiceList);
return mav;
服务类
@Transactional
public List<SpecialOrder> getSpecialOrder(List<Integer> invoiceList) throws ConnectException
List<SpecialOrder> getspecialorder = new ArrayList<>();
Session session = sessionFactory.getCurrentSession();
String hSql = "Select partnumber, partdescription, invoicenumber, quantity " + "from invoicedetails i, parts p "
+ "WHERE i.invoicenumber in :invoiceList, i.partnumber = p.partNo AND quantity < 0 ";
Query query = session.createQuery(hSql);
query.setParameterList("invoiceList", invoiceList);
getspecialorder = query.list();
session.flush();
session.clear();
return getspecialorder;
【问题讨论】:
【参考方案1】:我检查了https://www.eversql.com/sql-syntax-check-validator/ 的查询,它不喜欢用逗号代替 AND(实际上在您收到的错误消息中的位置 129),并希望 in
后面跟括号中的内容 (它也不喜欢冒号,但那是因为它是 SQL 而不是 HQL 所以不理解参数)。它确实接受以下内容(没有冒号,我在之后恢复了)。
Select
partnumber,
partdescription,
invoicenumber,
quantity
from
invoicedetails i,
parts p
WHERE
i.invoicenumber in (:invoiceList)
AND i.partnumber = p.partNo
AND quantity < 0
我认为应该适合你。
【讨论】:
以上是关于HTTP 状态 500 - 意外令牌:,靠近第 1 行,第 129 列的主要内容,如果未能解决你的问题,请参考以下文章
意外的令牌:在休眠状态下使用 spring data jpa 时的位置
如何在 Alamofire Swift 中刷新 JWT 令牌状态代码 500