Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problems of mybatis using Integer type query

Shulou Source: shulou.com Published: 2022-06-01 05:58:29 10月27日 Update

In this article Xiaobian for you to introduce in detail "mybatis using Integer type query how to solve the problem", detailed content, clear steps, details handled properly, I hope that this "mybatis using Integer type query how to solve the problem" article can help you solve doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.

Problems with using Integer type queries

Mapper.xml:

Select count (m.id) from hr_push_msg_model as m m.text like'% ${page.keyword}% 'and m.text like' ${page.entity.text}%' And m.title like'% {page.entity.title}% 'and m.state = # {page.entity.state} and m.type = # {page.entity.type}

For example:

And m.state = # {page.entity.state} when the state value is 0

Mybatis defaults to the empty string "", so if a similar scenario like state is worth it, don't add xxxxxexamples = "" to the query. Or or xxx==0.

Code example:

1 、

And m.state = # {page.entity.state}

2 、

And m.state = # {page.entity.state} mybatis to determine the output of bug scenarios encountered by Integer

All users with status 0 need to be found out.

That's what I wrote.

1.mapper:

BaseUser selectUserByStatus (@ parm ("status") Integer status)

There's a zero in here.

2.sql:

SELECT * FROM base_user WHERE status=0

3.xml fragment

Status = # {status}

4. As a result, the sql actually executed

SELECT * FROM base_user

A brief summary:

Test= "status! = null and status! =''" this is used to judge String! In other words, the same situation can happen to numeric types such as Double,BigDecimal.

1. If it is of type Integer, if the value of the variable is 0, that is, num = 0, mybatis will think that the value of num is an empty string when performing num! =''"; skip the judgment directly

So if it is Integer type, you only need to judge! = null.

two。 If the String type needs to be judged to be not equal to 0, you need to write name! = '0'.toString (), otherwise an error will be reported.

Read here, this "mybatis using Integer type query how to solve the problem" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to follow the industry information channel.

Tags: Type query question article content scene time status empty character proper that is code variables summary ideas situations numbers new knowledge more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Shulou Tech Info Microsoft NVidia