【第十五章】 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 ...
随机推荐
- 【Python】【web.py】python web py入门-4-请求处理(上)
python web py入门-4-请求处理(上) 2017年09月05日 23:07:24 Anthony_tester 阅读数:2907 标签: webpy入门请求处理 更多 个人分类: Pyth ...
- (3.5)mysql基础深入——mysqld_safe脚本功能及流程
(3.5)mysql基础深入——mysqld_safe脚本功能及流程 目录 1.mysqld_safe过程总结 2.mysql_safe启动的好处 3.mysqld_safe 参数 4.mysqld_ ...
- go for cryptocurrency
https://blog.conformal.com/category/btcd/ https://github.com/btcsuite/btcd/tree/master/docs https:// ...
- redis 在windows 上面的安装和使用,集群搭建
redis作为nosql数据库,将数据存储到内存中(缓存),具有非常高的性能.下面讲解一下redis的安装及java api的使用. 1:redis 安装 windows 上面直接下载msi文件,安装 ...
- ssm后台开发及发布
本文详细讲解一下后台的创建及发布过程,包括踩过的坑 1:首先创建war包形式的maven工程 File>new>Maven project>Create a simple proje ...
- mybatis中获取参数
1.${parameter}方式: parameter是数字时用:模糊查询%${parameter}%时用. 例:select * from account where userId = ${para ...
- Selenium+Java元素定位之二
//通过完全匹配链接来定位 driver.findElement(By.linkText("新闻")).click(); //通过部分匹配链接来定位 driver.findElem ...
- 代码编译 Compile、Make、Build 的区别
代码编译 Compile.Make.Build 的区别 https://blog.csdn.net/fanzheng220112583/article/details/7780250 VC++6.0中 ...
- java的poi技术读取Excel数据
这篇blog主要是讲述java中poi读取excel,而excel的版本包括:2003-2007和2010两个版本, 即excel的后缀名为:xls和xlsx. 读取excel和MySQL相关: ja ...
- linux系统安装 dig和nslookup命令
Fedora / Centos:1.yum install bind-utils Ubuntu: 1.sudo apt-get install dnsutils Debian: 1.2 apt-get ...