Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the error report of parameter transmission of mybatis group by substr function

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to solve the error report of mybatis group by substr function". The editor shows you the operation process through the actual case, the operation method is simple and fast, and it is practical. I hope this article "how to solve the error report of mybatis group by substr function" can help you solve the problem.

Abnormal misreport of mybatis group by substr parameter transmission

# Cause: java.sql.SQLSyntaxErrorException: ORA-00979: not an GROUP BY expression

SELECT SUBSTR (region_code,1,# {queryMap.groupCodeLength,jdbcType = INTEGER}) AS "region_code", count (CASE WHEN TYPE = 1 THEN 0 END) AS "like", count (CASE WHEN TYPE = 2 THEN 0 END) AS "roast" FROM t_pub_sentiment WHERE 1 = 1 GROUP BY SUBSTR (region_code,1,# {queryMap.groupCodeLength,jdbcType = INTEGER})

After change:

SELECT SUBSTR (region_code, 1, ${queryMap.groupCodeLength}) AS "region_code", count (CASE WHEN TYPE = 1 THEN 0 END) AS "like", count (CASE WHEN TYPE = 2 THEN 0 END) AS "roast" FROM t_pub_sentiment WHERE 1 = 1 GROUP BY SUBSTR (region_code, 1, ${queryMap.groupCodeLength}) reason

# {} and ${} are treated differently in precompilation. # {} will the parameter part be preprocessed with a placeholder? Instead. And ${} is just a simple string substitution.

${} has the risk of sql injection and should be used with caution.

Using a group by grouping query to return as null

When I use mybatis for grouping queries, the database has data, but mybatis returns null, using mybatis version 3.4.1

Solution method

Add the property attribute to the result tag of resultMap

As follows:

Select id,dept_name,count (1) from tbl_dept where dept_id=# {id} group by id

The fact that I didn't add property the first time I used it caused mybatis to return null, which can be returned normally after adding it.

Dao layer code

Public List getDeptByIdStep (Integer id); this is the end of the introduction of "how to solve the parameter error of mybatis group by substr function". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report