Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Example Analysis of numeric string alignment in mybatis

Shulou Source: shulou.com Published: 2022-06-01 06:41:27 09月25日 Update

Xiaobian to share with you the mybatis numerical string comparison example analysis, I hope you have something to gain after reading this article, let's discuss it together!

During the development of mybatis, it is necessary to determine which table to query in sql, as follows: sql:

SELECT a.tag_name, a.tag_id, count( 0 ) AS base_total FROM mm_dd_body a LEFT JOIN ccc AS b ON b.tag_body_id = a.id WHERE a.tag_base_cat = #{tagType} AND a.del = 0

At runtime, it is found that no matter what value tagType passes, it will not enter the two if. After analysis,'1' will be converted to a number, so there are two schemes here: Scheme 1: convert the parameter to int type, and then compare.

LEFT JOIN ccc AS b ON b.tag_body_id = a.id

Option 2: Convert numbers to strings, add.toString(), as follows:

LEFT JOIN ccc AS b ON b.tag_body_id = a.id

Of course, the above design is not a good design. It violates the principle of single responsibility. You can separate the if judgment into two separate selects, and then judge which one to use at the business layer. This is also a good solution, which can avoid many pits.

After reading this article, I believe you have a certain understanding of "mybatis numerical string comparison example analysis", if you want to know more related knowledge, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Numbers schemes characters strings analysis examples two articles design business principles parameters done more knowledge types responsibilities industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Apple Redmi Huawei