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

An example Analysis of mybatis sum column names as parameters

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

Share

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

In this article, the editor introduces in detail the "case analysis of mybatis sum listing as a parameter", with detailed content, clear steps and proper handling of details. I hope that this "case analysis of mybatis sum listing as a parameter" article can help you solve your doubts.

Sum (parameter) column name as parameter

There are many fields in the project, and when the field is empty, average the column and assign a value to the field. Such as:

Idnameage

When I need to insert a piece of data, the age of the data is empty, so I need to query the average of the age from the database and then assign the value to the current data. When there are many fields, you need to query the column name as a parameter.

Mapper.xml

Select avg (${columnName}) from tb_chuai where ${columnName} > 0

DAO

BigDecimal getGtAvg (@ Param ("columnName") String columnName); notes

1. Aggregate functions, such as sum, avg, etc. ResultType are bigDecimal or integer.

2. ${} is generally used to transfer database table names, field names, etc., and cannot use # {}

3. Varchar in mysql can perform operations such as sum,avg, but there may be problems when calculating the average value of avg when the Chinese character is taken as 0.

Mybatis annotation sql sum (parameter) transfer parameter writing method

It has been verified for a long time that the parameter mode # {parameter} in sum () has not worked all the time. The log shows that the parameter has been passed but cannot be added. The value returned is always 0.

Then change it to $(parameter).

@ Select ("select sum (${type}) from" + TABLE_HOUR + "where date_format (`date`,'% Ymuri% mmi% d') = # {date}") public int selectDay2 (@ Param ("date") String date,@Param ("type") String type) After reading this, the article "case Analysis of mybatis sum listing as a Parameter" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

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