当前位置:网站首页>ss-1.curl (cloud-provider-payment8001)
ss-1.curl (cloud-provider-payment8001)
2022-08-03 05:09:00 【lhorse003】
数据库
对payment表插入及获取
CREATE TABLE `payment` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', `serial` varchar(200) DEFAULT NULL COMMENT '支付流水号', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='支付表'
application.yml
server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: 123456
mybatis:
mapper-locations: classpath:mapper/*.xml type-aliases-package: com.cmk.springCloud.entities
entities
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/entities/CommonResult.java:13:1
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {
//404 not_cound
private Integer code;
private String message;
private T data;
public CommonResult(Integer code, String message) {
// this.code = code;
// this.message = message;
this(code,message,null);
}
}
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/entities/Payment.java:15:1
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment implements Serializable {
private long id;
private String serial;
}
dao
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/dao/PaymentDao.java:13:1
@Mapper
public interface PaymentDao {
int create(Payment payment);
Payment getPaymentById(@Param("id") long id);
}
mapper
//jetbrains://idea/navigate/reference?project=zy2020&path=mapper/PaymentMapper.xml:1:1
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cmk.springCloud.service.PaymentService">
<insert id="create" parameterType="com.cmk.springCloud.entities.Payment">
insert into payment(serial) values (#{
serial});
</insert>
<select id="getPaymentById" parameterType="long" resultMap="BaseResultMap">
select * from payment where id=#{
id}
</select>
<resultMap id="BaseResultMap" type="com.cmk.springCloud.entities.Payment">
<id column="id" property="id" jdbcType="BIGINT"/>
<id column="serial" property="serial" jdbcType="VARCHAR"/>
</resultMap>
</mapper>
service
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/service/PaymentService.java:13:1
@Mapper
public interface PaymentService {
int create(Payment payment);
Payment getPaymentById(@Param("id") long id);
}
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/service/impl/PaymentServiceImpl.java:17:1
@Service
public class PaymentServiceImpl implements PaymentService {
@Resource
private PaymentDao paymentDao;
public int create(Payment payment){
return paymentDao.create(payment);
}
public Payment getPaymentById(@Param("id") long id){
return paymentDao.getPaymentById(id);
}
}
controller
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/controller/PaymentController.java:14:1
@RestController
@Slf4j
public class PaymentController {
@Resource
private PaymentService paymentService;
@PostMapping("/payment/create")
public CommonResult create(Payment payment){
int result = paymentService.create(payment);
log.info("****插入结果"+result);
if (result>0){
return new CommonResult(200,"插入数据库成功",result);
}else{
return new CommonResult(400,"插入数据库失败",null);
}
}
@GetMapping("/payment/get/{id}")
public CommonResult getPaymentById(@PathVariable("id") long id){
Payment result = paymentService.getPaymentById(id);
log.info("****查询结果"+result);
if (result !=null){
return new CommonResult(200,"查询数据库成功",result);
}else{
return new CommonResult(400,"查询数据库失败",null);
}
}
}
main
//jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/PaymentMain8001.java:12:1
@SpringBootApplication
public class PaymentMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8001.class,args);
}
}
边栏推荐
- Talking about GIS Data (6) - Projected Coordinate System
- Coordinate knowledge in digital twin campus scenarios
- 【Harmony OS】【ARK UI】轻量级数据存储
- Detailed explanation of MOSN reverse channel
- Interface test framework combat (1) | Requests and interface request construction
- 技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
- 1079 延迟的回文数 (20 分)
- 建造者模式(Builder Pattern)
- 1060 爱丁顿数 (25 分)
- 1069 微博转发抽奖 (20 分)(C语言)
猜你喜欢
测试人员的价值体现在哪里
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
Super handy drawing tool is recommended
内部类、static关键字、final
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
【Harmony OS】【FAQ】Hongmeng Questions Collection 1
[Harmony OS] [ArkUI] ets development graphics and animation drawing
Alienware上线首个数字时装AR试穿体验
How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
随机推荐
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
信息编码、存储压缩与密码学
接口测试框架实战(二)| 接口请求断言
idea使用@Autowired注解爆红原因及解决方法
shell script loop statement
Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
shell脚本循环语句
C#异步和多线程
接口管理工具YApi怎么用?颜值高、易管理、超好用
Harmony OS Date ano UI 】 【 】 the basic operation
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
User password verification
typescript46-函数之间的类型兼容性
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
数字孪生园区场景中的坐标知识
MySql数据库
odps的临时查询能在写sql的时候就给结果一个命名不?
Power button 561. An array of split
Talking about GIS Data (5) - Geographic Coordinate System
c语言结构体中的冒泡排序