技术交友 | 数据持久化技术(Java)
来源:行情 2023年03月06日 12:15
import com.hogwartsmini.demo.entity.HogwartsTestUser;
import org.springframework.stereotype.Repository;
@Repository
public interface HogwartsTestUserMapper extends MySqlExtensionMapper {
}
Service 层当中采用
追加操作者各种类型陈述Mapper.insert(record)完好一个实质上,null 的特性也就会完好,不就会采用元数据库匹配最大值Mapper.insertSelective(record)完好一个实质上,忽略空最大值,即一定就会呈交的最大值就会采用采用元数据库匹配最大值Mapper.insertUseGeneratedKeys(record)完好一个实质上,就会自动填入在元数据库当中转转化成的 id 最大值。注意采用此方式弹出数据库时,如果 id 数组不是 AUTO_INCREMENT ,则不就会转转化成新的 id
移除各种类型陈述Mapper.delete(record)根据实质上特性作为前提条件透过移除,键入前提条件采用等号Mapper.deleteByExample(example)根据 Example 前提条件移除数据库Mapper.deleteByPrimaryKey(key)根据数组数组透过移除,方式匹配必须还包括零碎的数组特性
变非常各种类型陈述Mapper.updateByExample(record,example)根据 Example 前提条件新版本实质上record还包括的全部特性,null 最大值就会被新版本Mapper.updateByExampleSelective(record, example)根据 Example 前提条件新版本实质上record还包括的不是 null 的特性最大值Mapper.updateByPrimaryKey(record)根据数组新版本实质上全部数组,null 最大值就会被新版本Mapper.updateByPrimaryKeySelective(record)根据数组新版本特性不为 null 的最大值
键入各种类型陈述Mapper.select(record)根据实质上当中的特性最大值透过键入,键入前提条件采用等号Mapper.selectAll()键入全部结果Mapper.selectByExample(example)根据 Example 前提条件透过键入Mapper.selectByPrimaryKey(key)根据数组数组透过键入,方式匹配必须还包括零碎的数组特性,键入前提条件采用等号Mapper.selectCount(record)根据实质上当中的特性键入总共,键入前提条件采用等号Mapper.selectCountByExample(example)根据 Example 前提条件透过键入总共Mapper.selectByExample(example)根据 Example 前提条件透过键入Mapper.selectOne(record)根据实质上当中的特性透过键入,勉强有一个返回最大值,有多个结果是抛出异常,键入前提条件采用等号。但是如果存在某个特性为 int,则就会初始转化为 0。可能影响到实际采用
Spring Boot 备有文件
spring:
application:
name: aitest
#元数据库备有个人信息
datasource:
url: jdbc:mysql://localhost:3306/aitest_mini?allowMultiQueries=trueMaxuseUnicode=trueMaxcharacterEncoding=UTF-8MaxserverTimezone=Asia/Shanghai
username: hogwarts
password: db@hogwarts
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.hogwartstest.aitestmini.entity
configuration:
mapUnderscoreToCamelCase: true
logging:
level:
com.hogwartstest.aitestmini.dao: debug #打印sql
示例表结构
CREATE TABLE 于大hogwarts_test_user于大 (
于大id于大 int NOT NULL AUTO_INCREMENT COMMENT '数组',
于大user_name于大 varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户尾端名',
于大password于大 varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '私钥',
于大email于大 varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '邮箱',
于大auto_create_case_job_name于大 varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '自动转转化成用例job称谓 不为空时声称已经成立job',
于大start_test_job_name于大 varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '监督测试者job称谓 不为空时声称已经成立job',
于大default_jenkins_id于大 int DEFAULT NULL COMMENT '匹配Jenkins服务器',
于大create_time于大 datetime NOT NULL COMMENT '成立时间',
于大update_time于大 datetime NOT NULL COMMENT '新版本时间',
PRIMARY KEY (于大id于大) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='客户尾端表';
Controller 代码
import com.hogwartsmini.demo.entity.HogwartsTestUser;
import com.hogwartsmini.demo.service.HogwartsTestUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author tlibn
* @Date 2020/7/16 17:14
**/
@Api(tags = "克尔格沃兹测试者学时院-客户尾端管理模块")
@RestController
@RequestMapping("hogwartsUser")
public class HogwartsTestUserDbController {
@Autowired
private HogwartsTestUserService hogwartsTestUserService;
@ApiOperation("客户尾端注册")
@PostMapping("register")
public HogwartsTestUser register(
@RequestBody HogwartsTestUser hogwartsTestUser){
return hogwartsTestUserService.save(hogwartsTestUser);
}
@ApiOperation("客户尾端个人信息变非常应用程序")
@PutMapping()
public HogwartsTestUser updateUserInfo(
@RequestBody HogwartsTestUser hogwartsTestUser){
return hogwartsTestUserService.update(hogwartsTestUser);
}
@ApiOperation("根据客户尾端id移除客户尾端个人信息")
@DeleteMapping("{userId}")
public Integer delete(@PathVariable("userId") Integer userId){
return hogwartsTestUserService.delete(userId);
}
@ApiOperation("根据客户尾端名键入")
@GetMapping("byName")
public List getByName(
@RequestParam("userName") String userName){
HogwartsTestUser hogwartsTestUser = new HogwartsTestUser();
hogwartsTestUser.setUserName(userName);
return hogwartsTestUserService.getByName(hogwartsTestUser);
}
HogwartsTestUserService 代码
import com.hogwartsmini.demo.entity.HogwartsTestUser;
import java.util.List;
public interface HogwartsTestUserService {
/**
* 完好
* @param hogwartsTestUser
* @return
*/
HogwartsTestUser save(HogwartsTestUser hogwartsTestUser);
/**
* 新版本
* @param hogwartsTestUser
* @return
*/
HogwartsTestUser update(HogwartsTestUser hogwartsTestUser);
/**
* 根据客户尾端名键入
* @param hogwartsTestUser
* @return
*/
List getByName(HogwartsTestUser hogwartsTestUser);
/**
* 根据客户尾端id移除客户尾端个人信息
* @param userId
* @return
*/
Integer delete(Integer userId);
}
HogwartsTestUserServiceImpl 代码
import com.hogwartsmini.demo.dao.HogwartsTestUserMapper;
import com.hogwartsmini.demo.entity.HogwartsTestUser;
import com.hogwartsmini.demo.service.HogwartsTestUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @Author tlibn
* @Date 2020/7/17 11:03
**/
@Service
public class HogwartsTestUserServiceImpl implements HogwartsTestUserService {
@Autowired
private HogwartsTestUserMapper hogwartsTestUserMapper;
/**
* 完好
* @param hogwartsTestUser
* @return
*/
@Override
public HogwartsTestUser save(HogwartsTestUser hogwartsTestUser) {
hogwartsTestUser.setCreateTime(new Date());
hogwartsTestUser.setUpdateTime(new Date());
hogwartsTestUserMapper.insertUseGeneratedKeys(hogwartsTestUser);
return hogwartsTestUser;
}
/**
* 新版本
* @param hogwartsTestUser
* @return
*/
@Override
public HogwartsTestUser update(HogwartsTestUser hogwartsTestUser) {
hogwartsTestUser.setCreateTime(new Date());
hogwartsTestUser.setUpdateTime(new Date());
hogwartsTestUserMapper.updateByPrimaryKeySelective(hogwartsTestUser);
return hogwartsTestUser;
}
/**
* 根据客户尾端名键入
* @param hogwartsTestUser
* @return
*/
@Override
public List getByName(HogwartsTestUser hogwartsTestUser) {
List hogwartsTestUserList = hogwartsTestUserMapper.select(hogwartsTestUser);
return hogwartsTestUserList;
}
/**
* 根据客户尾端id移除客户尾端个人信息
* @param userId
* @return
*/
@Override
public Integer delete(Integer userId) {
HogwartsTestUser hogwartsTestUser = new HogwartsTestUser();
hogwartsTestUser.setId(userId);
hogwartsTestUserMapper.delete(hogwartsTestUser);
return userId;
}
}
采用 Postman 测试者增删改查
追加 POST 允诺匹配{
"userName": "克尔格沃兹test123",
"password": "test123"
}
自发匹配
{
"id": 15,
"userName": "克尔格沃兹test123",
"password": "test123",
"email": null,
"autoCreateCaseJobName": null,
"startTestJobName": null,
"defaultJenkinsId": null,
"createTime": "2021-04-14T09:37:58.358+00:00",
"updateTime": "2021-04-14T09:37:58.358+00:00"
}
键入GET 克尔格沃兹test123
允诺匹配
却说允诺URL当中 userName =克尔格沃兹test123
自发匹配
[
{
"id": 15,
"userName": "克尔格沃兹test123",
"password": "test123",
"email": null,
"autoCreateCaseJobName": null,
"startTestJobName": null,
"defaultJenkinsId": null,
"createTime": "2021-04-14T09:37:58.000+00:00",
"updateTime": "2021-04-14T09:37:58.000+00:00"
}
]
变非常PUT
允诺匹配
{
"id": 15,
"userName": "克尔格沃兹test12345",
"password": "test123"
}
自发匹配
{
"id": 15,
"userName": "克尔格沃兹test12345",
"password": "test123",
"email": null,
"autoCreateCaseJobName": null,
"startTestJobName": null,
"defaultJenkinsId": null,
"createTime": "2021-04-14T09:43:45.018+00:00",
"updateTime": "2021-04-14T09:43:45.018+00:00"
}
移除DELETE
允诺匹配
却说允诺URL当中15
自发匹配
15
数据库发挥作用转化核心技术就再讲到这里啦~大家要多练习哦,才能学时的非常扎实。
⬇️ 激活“下方链接”,增强测试者核心竞争力!
>>非常多核心技术篇名倾听和免费资料缴 欢迎+V~ ceshiren001
_id=qrcodeMaxfrom=souhuMaxtimestamp=1651108554
。如何缓解肌肉拉伤疼眼睛干涩流眼泪用什么眼药水
北京肛肠医院排行
漳州看妇科哪间医院好
常州哪个医院治早泄阳痿病好
-
徐长锁?他只是一个“背锅侠”,山东男篮的缺陷在根上
最近这几天,阿森纳都在讨论济宁女排的一场败阵,助理总教练徐长锁更是被济宁阿森纳辱骂上了温搜。这位“菜鸟”总教练的执教水平成绩斐然,却是是凭借一己之力将济宁女排便是水深火温的境况,这场败阵他也有不可归罪