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 understand the date attribute of springboot pojo object

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to understand the date attribute of springboot pojo object". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the date attribute of springboot pojo object".

Catalogue

Pojo object date property

Pojo default settings

Pojo Settings (recommended)

Pojo object date property

The FeignClient date property is maintained with pojo, using the Date type

The value of the pojo attribute is annotated JsonFormat, and the property obtained by the front end is the formatted value.

@ JsonFormat (timezone = DateUtils.TIMEZONE, pattern = DateUtils.DATE_TIME_FORMATE) private Date date;pojo default setting

We sometimes need to set default values for POJO

Pojo Settings (recommended)

1 、 User

Package com.xxx.firstboot.domain;import lombok.Getter;import lombok.Setter;@Getter@Setterpublic class User {private int id; private String username = ""; / / set default value private String password = ""; / / set default value}

2 、 UserController

@ ApiOperation ("add user / test POJO defaults") @ RequestMapping (value= "/ addUserWithNoParam", method=RequestMethod.POST) public boolean addUserWithNoParam () {return userService.addUserWithNoParam (new User ()); / / only new, no value}

3 、 UserService

Public boolean addUserWithNoParam (User user) {return userDao.insertUserWithUserParam (user) > zero true false;}

4 、 UserDao

Public int insertUserWithUserParam (User user) {return userMapper.insertUserWithUserParam (user);}

5 、 UserMapper

Insert ("INSERT INTO tb_user (username, password) VALUES (# {username}, # {password})") public int insertUserWithUserParam (User user)

Testing: viewing database

If the database also sets the default value, as follows

Execute the above procedure again, and find that the result is the same as above, because although we did not pass the values of username and password of pojo, the default value is set to "" in the User class. In this case, when it is transferred to the database, username is not actually null, then the default value of mysql will not be used.

Thank you for your reading, the above is the content of "how to understand the date attribute of springboot pojo object". After the study of this article, I believe you have a deeper understanding of how to understand the date attribute of springboot pojo object. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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