数据库的那些事儿
pojo 实体类
mapper。xml有问题:
Q:Dict_id 自动顺序增长,而不是自己设的值。
A:
为啥发出请求加东西,实际却没有加到数据库呢?因为我adddic 函数还没写昂。
接下来,做删除功能。
遇到过的错误 Q & A:
There is no getter for property named ‘dict_uuid’ in ‘class com.jj.red.packet.user.mybatis.domain.RoundDict’
There is no getter for property named ‘dict_key’ in ‘class com.jj.red.packet.user.mybatis.domain.RoundDict’
DEBUG [com.jj.red.packet.user.mybatis.persistence.RoundDictMapper.insertSelective] - ==> Preparing: insert into t_round_dict ( dictUuid, dictKey, dictDetail ) values ( ?, ?, ? )
Q:增和删,mapper都返回1,能改吗?
[com.jj.red.packet.user.mybatis.persistence.RoundDictMapper.insert] - <== Updates: 1
A: resultType:适合使用返回值的数据类型是非自定义的,即jdk的提供的类型 –>
|
Q: list 为啥没有返回items;
|
验证dict_id不能为null,不然抛出异常
java.lang.RuntimeException: Value for dict_id cannot be null
at com.jj.red.packet.user.mybatis.domain.RoundDictExample$GeneratedCriteria.addCriterion(RoundDictExample.java:95)
at com.jj.red.packet.user.mybatis.domain.RoundDictExample$GeneratedCriteria.andDictIdEqualTo(RoundDictExample.java:118)
at com.jj.red.packet.user.mybatis.domain.RoundDictExample$Criteria.andDictIdEqualTo(RoundDictExample.java:763)
at com.jj.red.packet.user.service.impl.RoundDictServiceImpl.getDicts(RoundDictServiceImpl.java:55)
Q:Unknown column ‘xxx’ in ‘field list’
A:数据表中字段与实体类中声明的字段对象没有用注解连接。
或者 将两个名字改成一致的
Q:不知道哪个是对应数据库的键,哪个对应实体类的键
A:
|
tips;UUID : VARCHAR(36)类型
终端打印出来的顺序;
ApplicationContext –> ContextLoader –> ServletREgistrationBean –> dispatcherServlet –> RequestMappingHandlerMapping –> Mapped (/m/add method=[POST]) to. ResponseMessage –> xxController.add ; url path [/v2/api] to SwaggerController.getDocument –> … —> tomcat started on port xxx
LIST
|
Controller: roundDictService .getDicts –> roundDictServiceImpl .getDicts( roundDictMapper.selectByExample(example) ) –> mappler. selectByexample–> mapper.xml id = selectByexample
快看原来返回的是什么模型就已经告诉我了
list :
==list
|
roundDictService.getDicts( ) –>
Page
|
page类 :setStart
SysPageBean : setItems
pageBean: setItems
Corecontroller: roundDicts 需要有一个 getItems()方法
|
注解 for swagger
|
常用注解:https://github.com/Mshuyan/swagger
https://blog.csdn.net/weixin_44906271/article/details/105792809
=====add
|
有JDBC操作经验的朋友可能会有印象,增删改操作实际上返回的是操作的条数。而Mybatis框架本身是基于JDBC的,所以此处也沿袭这种返回值类型。
返回模型:ResponseMessage«Map» {
resultStatus (code:1000,message:成功) :getStatus,getcode/Message
自定义(getDictId)
return map(code,message)
–>
ResponseMessage( ) :ResponseMessage( resultStatus.自定义(getDictId) ) getData()
return map( code,message, dictId, dictum ….)
——》
Controller ()
Return ResponseMessage
responsebody?
\
发现我 “roomId”: 0, “userId”: 0 已经成功删掉了,唯有action还很坚挺,可能在父类里面定义了。
资料:
mapper.xml中常用的标签详解:https://blog.csdn.net/qq_29233973/article/details/51433924
https://www.cnblogs.com/aichiboluo/p/8962529.html
深入解析mapper.xml: https://lanlan2017.github.io/JavaReadingNotes/f097c266/