cloud-provider-payment-8001搭建
1.建module
2.改pom
3.写yml
4.写run
5.写业务
yml配置文件
server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
url: jdbc:mysql://localhost:3306/db2020?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 12345678
type: com.alibaba.druid.pool.DruidDataSource
#配置mybatis
mybatis:
#设置别名
mapperLocations: classpath:mapper/*.xml
type-aliases-package: com.yan.springcloud.pojo
configuration:
map-underscore-to-camel-case: true #开启这个的作用是可以让数据库中的p_Addr与pojo中的pAddr对应
mapper,注意:namesapce与dao接口名一致,id与方法名一致,主启动类加@mapperscan注解
<?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.yan.springcloud.dao.PaymentDao">
<!-- 这里的useGeneratedKeys是如果创建成功返回1,失败返回0的作用-->
<insert id="create" parameterType="Payment" useGeneratedKeys="true" keyProperty="id">
insert into payment(serial) values(#{serial});
</insert>
<!-- 配置结果集的映射-->
<resultMap id="BaseResultMap" type="com.yan.springcloud.pojo.Payment">
<id column="id" property="id" jdbcType="BIGINT"/>
<id column="serial" property="serial" jdbcType="VARCHAR"/>
</resultMap>
<select id="getPaymentById" parameterType="Long" resultMap="BaseResultMap">
select * from payment where id=#{id};
</select>
</mapper>
关于Required request body is missing的原因
使用postman测试是不能单纯只选择请求方式为post,还应该把请求体以json格式写在下面