我们有时需要给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默认值设置的更多相关文章

  1. 【第十五章】 springboot + pojo默认值设置

    我们有时需要给POJO设置默认值 pojo设置(推荐) 1.User package com.xxx.firstboot.domain; import lombok.Getter; import lo ...

  2. 第二十五章 springboot + hystrixdashboard

    注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...

  3. 【第二十五章】 springboot + hystrixdashboard

    注意: hystrix基本使用:第十九章 springboot + hystrix(1) hystrix计数原理:附6 hystrix metrics and monitor 一.hystrixdas ...

  4. “全栈2019”Java第六十五章:接口与默认方法详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  5. 《Linux命令行与shell脚本编程大全》 第十五章 学习笔记

    第十五章:控制脚本 处理信号 重温Linux信号 信号 名称 描述 1 HUP 挂起 2 INT 中断 3 QUIT 结束运行 9 KILL 无条件终止 11 SEGV 段错误 15 TERM 尽可能 ...

  6. CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章

    第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...

  7. Gradle 1.12 翻译——第十五章. 任务详述

    有关其他已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或访问:http://gradledoc.qiniudn.com ...

  8. Gradle 1.12用户指南翻译——第二十五章. Scala 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  9. Gradle 1.12用户指南翻译——第三十五章. Sonar 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

随机推荐

  1. 2011年入侵 Kernel.org 的黑客被捕 面临10年监禁

    2011年中旬,Linux内核官网kernel.org遭到黑客入侵,攻击者植入了rootkit Phalanx,并在服务器上设置了SSH后门,kernel.org为此关闭了三周多时间.官方表示将会公开 ...

  2. js根据IP跳转

    <script language="javascript" type="text/javascript" src="http://int.dpo ...

  3. python 关键知识点

    学习资源:笨方法学习 python3 将变量传递给脚本--argv 脚本:你编写的 .py 文件. argv 参数变量(argument variable)保存着你运行 python 脚本的参数. i ...

  4. eclipse 设置文本模板中 insert variable... 函数 详解

    设置文本模板简要图: 设置文本模板详细过程:http://www.cnblogs.com/lsy131479/p/8478711.html 此处引出设置文本模板中 insert variable... ...

  5. php开启redis扩展

    1.安装redis git下载地址https://github.com/MSOpenTech/redis/releases 2.测试redis windows 运行(快捷键:windows键+R键), ...

  6. 【WIN10】使用VS生成appx安裝包,並安裝測試

    就算沒有微軟開發者帳號,我們也是可以創建appx的. 只不過有了帳號,我們可以把這個APPX與商店中的應用關聯,並上傳,方便許多罷了. 下面就說步驟: 1.生成appx 1)菜單:項目->應用商 ...

  7. 「NOI2014」购票

    「NOI2014」购票 解题思路 先列出 \(dp\) 式子并稍微转化一下 \[ dp[u] =\min(dp[v]+(dis[u]-dis[v]) \times p[u] + q[u])) \ \ ...

  8. python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

    我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...

  9. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  10. C# 高级编程9 第30章MEF C#可扩展编程之MEF第2章(抄录)

    Managed Extensibility Framework (MEF) 什么是 MEF?   Managed Extensibility Framework 即 MEF 是用于创建轻量.可扩展应用 ...