惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
O
OpenAI News
Forbes - Security
Forbes - Security
W
WeLiveSecurity
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
P
Privacy & Cybersecurity Law Blog
The Register - Security
The Register - Security
T
Tor Project blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Secure Thoughts
D
DataBreaches.Net
Vercel News
Vercel News
D
Docker
T
The Blog of Author Tim Ferriss
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
LangChain Blog
博客园_首页
S
Schneier on Security
宝玉的分享
宝玉的分享
Project Zero
Project Zero
V
Visual Studio Blog
Attack and Defense Labs
Attack and Defense Labs
量子位
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
B
Blog
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
Latest news
Latest news
P
Proofpoint News Feed
Help Net Security
Help Net Security
Schneier on Security
Schneier on Security
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
有赞技术团队
有赞技术团队
B
Blog RSS Feed
Last Week in AI
Last Week in AI
C
Cyber Attacks, Cyber Crime and Cyber Security
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog

博客园 - sleepy

Android 下进行单元测试 Test run failed:Instrumentation run failed due to 'java.lang.ClassNotFoundException' 使用Maven自动部署Tomcat 6和Tomcat 7下Web应用 windows 7下命令行修改用户密码 VMWare Workstation 中Guest OS使用Bridge方式上网故障诊断 CSS guideline java下运行windows命令行程序(批处理文件)示例 - sleepy - 博客园 不用安装Oracle Client如何使用PLSQL Developer 新的 好用的 免费的 功能强大的Oracle 客户端 MySQl客户端访问软件 VPC 2007 SP1下安装Windows虚拟机要点(关键字:VM,Virtual PC, 网络,共享文件,windows 2003, vista, Window XP) tomcat 设置初始内存大小(默认的可是太小了,容易内存溢出) - sleepy - 博客园 测试显示内存使用情况的JSP脚本 在Virtual PC 2007 SP1上安装linux ubuntu 810 如何解决eclipse编辑器,console 汉字显示为乱码?? MySQL内置命令导出数据库 设置MySQL 超时等待时间 Java中访问My SQL如何显示SQL中的汉字 如何高效率修改bug 如何在MySql中记录SQL日志(例如Sql Server Profiler)
iBatis 数据库空值的映射处理
sleepy · 2008-12-25 · via 博客园 - sleepy

上次提到的iBatis关于空值的映射处理,primitive数据类型容易出现此问题,今天服务就因此问题造成无法启动。

我查了一下资料又做了验证,目前有两种方法可解决此问题:

1

使用映射xml的 nullValue 属性(attribute)。例如,下面红色标注的nullValue='0'指当表tb_role中栏目role_Max为数据库空时,设置相应bean对象属性为0;反之如果对象com.hp.hpe.service.dataService.dao.domain.Role的roleMax 属性(property)为0时, 新增/更新数据库时,使用数据库的null值进行更新。

 <resultMap id="result" class="com.hp.hpe.service.dataService.dao.domain.Role">
  <result property="roleId" column="role_id"/>
  <result property="roleName" column="role_name"/>
  <result property="roleMax" column="role_max" nullValue='0'/>
  <result property="roleContext" column="role_context"/>
  <result property="gameRound" column="game_round"/>
 </resultMap>

2 

另一种方法是不需要修改映射文件,修改bean的声明,使用primitive类型对应的封装对象类型。例如: int <--> Integer,此时Java的null 与 DB的null对应。

public Integer getRoleMax() {
  return roleMax;
 }
 public void setRoleMax(Integer roleMax) {
  this.roleMax = roleMax;
 }

当然,修改schema非空也是一种办法,anyway,请大家基于业务选择合适的方法。