@Select select a record with null columns,these columns are filled with columns' value that are not null
See original GitHub issueI am using myBatis in springboot web project, I got a table in my database like this:
I also have a bean class(User) has fields just like the table’s structure:
public class User {
public String loginId, loginPassword, name;
public String enrollTime, gender, address, email;
public User(String loginId, String loginPassword, String name, String gender, String address, String email) {
this.loginId = loginId;
this.loginPassword = loginPassword;
this.name = name;
this.gender = gender;
this.address = address;
this.email = email;
}
// getters and setters
}
myBatis mapper was written like this:
@Mapper
public interface UserMapper {
@Select("select * from users where loginId=#{loginId}")
public User GetUserByLoginId(@Param("loginId") String loginId);
}
When I call userMapper.GetUserByLoginId(“2”),myBatis give me the User object like this:
It can be seen that the address and email fileds should have been null but was filled by other fileds’ value. I wonder what’s the problem with MyBatis, should I add some other annotation to fix this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to SELECT Records With No NULL Values in MySQL
Use the MySQL engine to only grab records that you desire while excluding those with pesky NULL columns with the IS NOT NULL...
Read more >How to Filter Rows without NULL in a column | LearnSQL.com
Do this by using the IS NOT NULL operator. Solution: SELECT name ,. price.
Read more >How to display notnull rows and columns in a Python ...
To display not null rows and columns in a python data frame we are going to use different methods as dropna(), notnull(), loc[]....
Read more >Select columns with NULL values only - sql server
This takes a list of values and returns the first non-null value. If you add all the column names to the list, then...
Read more >SQL WHERE IS NULL | IS NOT NULL - Dofactory
WHERE IS NULL tests if a column has a NULL value. ... SELECT C.Id, FirstName, LastName, TotalAmount FROM Customer C LEFT JOIN [Order]...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I know what’s going on.As I continue to test, a field in my model has a slightly different name from that in my database field, which leads to null value mis-match. Apologize for wasting your time.
No,mapper should be correct. This problem occurs in mysql database when several fields are varchar, and some of the records among these columns are null. I solved the problem for now by modifying default value of varchar fileds in my database from null to to EMPTY_STRING. As soon as I complete the current on-going project, I’ll provide a repro. (Sorry for my being busy now, MyBatis is a still a powerful tool for me.Thanks for all of your developers’ hard work!)