【第十五章】 springboot + pojo默认值设置
我们有时需要给POJO设置默认值
- pojo设置(推荐)
1、User
package com.xxx.firstboot.domain;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class User {
private int id;
private String username = "";//设置默认值
private String password = "";//设置默认值
}
2、UserController
@ApiOperation("添加用户/测试POJO默认值")
@RequestMapping(value="/addUserWithNoParam",method=RequestMethod.POST)
public boolean addUserWithNoParam() {
return userService.addUserWithNoParam(new User());//只新建,不设值
}
3、UserService
public boolean addUserWithNoParam(User user){
return userDao.insertUserWithUserParam(user)>0?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);
测试:查看数据库

如果数据库也设置了默认值,如下

再次执行上述程序,发现结果还是如上,因为pojo的username和password的值我们虽然没有传,但是默认值在User类设为了"",这样的话,传到数据库,实际上username并不为null,那么也不会采用mysql的默认值了。
【第十五章】 springboot + pojo默认值设置的更多相关文章
- 第十五章 springboot + pojo默认值设置
我们有时需要给POJO设置默认值 pojo设置(推荐) 1.User package com.xxx.firstboot.domain; import lombok.Getter; import lo ...
- 第二十五章 springboot + hystrixdashboard
注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...
- 【第二十五章】 springboot + hystrixdashboard
注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...
- “全栈2019”Java第六十五章:接口与默认方法详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- 《Linux命令行与shell脚本编程大全》 第十五章 学习笔记
第十五章:控制脚本 处理信号 重温Linux信号 信号 名称 描述 1 HUP 挂起 2 INT 中断 3 QUIT 结束运行 9 KILL 无条件终止 11 SEGV 段错误 15 TERM 尽可能 ...
- CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章
第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...
- Gradle 1.12 翻译——第十五章. 任务详述
有关其他已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或访问:http://gradledoc.qiniudn.com ...
- Gradle 1.12用户指南翻译——第二十五章. Scala 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
- Gradle 1.12用户指南翻译——第三十五章. Sonar 插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
随机推荐
- qt——for循环里创建widget
在for循环里创建 widget,比如test类 不能使用 test t; 而要使用 test t = new test(): for (i=0;i<=3;i++) { QPushButton* ...
- dp训练
根据这位大佬的https://www.cnblogs.com/Bunnycxk/p/7360183.html 题目链接:https://www.luogu.org/problemnew/show/P3 ...
- PAT Spell It Right [非常简单]
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- iOS 网易彩票-3常见设置
Navigation导航设置 为了统一管理导航控制器,需要自定义导航控制器MJNavigationController,继承于UINavigationController.分别设置5个Navigati ...
- c/c++的预处理定义 Stringizing Operator (#) Charizing Operator (#@) Token-Pasting Operator (##)
c/c++的预处理定义:一.Stringizing Operator (#)在c和c++中数字标志符#被赋予了新的意义,即字符串化操作符.其作用是:将宏定义中的传入参数名转换成用一对双引号括起来参数名 ...
- 【安装vsftpd】安装vsftpd工具步骤
1 安装vsftpd组件 [root@bogon ~]# yum -y install vsftpd 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. 2 添 ...
- VS2010/MFC编程入门之五十(图形图像:GDI对象之画笔CPen)
上一节中鸡啄米讲了CDC类及其屏幕绘图函数,本节的主要内容是GDI对象之画笔CPen. GDI对象 在MFC中,CGdiObject类是GDI对象的基类,通过查阅MSDN我们可以看到,CGdiObje ...
- css3实现头像旋转360度
css样式: .div a img{ width: 88px; height: 88px; border-radius: 88px; transition: all 1.2s ease-out 0s; ...
- Intro to Python for Data Science Learning 2 - List
List from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-2-python-list ...
- ROS知识(2)----理解ROS系统结构
学习新事物,方法高于技术本身,如果没有把握"BIG PICTURE"的话很难理解进去.通过以下几点进行理解ROS: ROS实际上不是操作系统,他只是一个通信的框架,一个代码管理的架 ...