SpringCloud--支付模块
- 支付模块搭建:
-
-
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>SpringCloud</artifactId> <groupId>com.model</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud001-provider-payment8001</artifactId> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> </dependencies> </project>
-
-
package com.model; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 21:52 */ @SpringBootApplication public class PaymentMain8001 { public static void main(String[] args){ SpringApplication.run(PaymentMain8001.class, args); } }
-
CREATE TABLE payment( id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID' primary key, serial varchar(200) DEFAULT '' )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
-
package com.model.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 22:54 */ @Data @AllArgsConstructor @NoArgsConstructor public class Payment { private Long id; private String serial; }
-
package com.model.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 22:56 */ @Data @AllArgsConstructor @NoArgsConstructor public class CommonResult<T> { //404 private Integer code; private String message; private T data; public CommonResult(Integer code,String message){ this(code,message,null); } }
-
<?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.model.dao.PaymentDao"> <!-- 方法名,执行sql语句有的参数返回类型--> <insert id="create" parameterType="Payment" useGeneratedKeys="true" keyProperty="id"> insert into payment(serial) values(#{serial}) </insert> <select id="getPaymentById" resultMap="BaseResultMap" parameterType="Long"> select * from payment where id=#{id}; </select> <!-- 表的映射--> <resultMap id="BaseResultMap" type="com.model.pojo.Payment"> <id column="id" property="id" jdbcType="BIGINT"/> <id column="serial" property="serial" jdbcType="VARCHAR"/> </resultMap> </mapper>
-
package com.model.service.impl; import com.model.dao.PaymentDao; import com.model.pojo.Payment; import com.model.service.PaymentService; import org.springframework.stereotype.Service; import javax.annotation.Resource; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 23:22 */ @Service public class PaymentServiceImpl implements PaymentService { @Resource private PaymentDao paymentDao; @Override public Integer create(Payment payment) { return paymentDao.create(payment); } @Override public Payment getPaymentById(Long id) { return paymentDao.getPaymentById(id); } }
-
package com.model.controller; import com.model.pojo.CommonResult; import com.model.pojo.Payment; import com.model.service.PaymentService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 23:28 */ @Controller @Slf4j @RequestMapping("/payment") public class PaymentController { @Resource private PaymentService paymentService; @PostMapping("/create") public CommonResult create(Payment payment){ Integer result = paymentService.create(payment); log.info("插入结果:"+result); if (result>0){ return new CommonResult<>(200,"插入成功",result); } return new CommonResult(444,"插入失败",null); } @GetMapping("/getPaymentById/{id}") public CommonResult getPaymentById(@PathVariable("id")Long id){ Payment payment = paymentService.getPaymentById(id); log.info("插入结果:"+payment); if (payment!=null){ return new CommonResult(200,"查询成功",payment); } return new CommonResult(444,"查询失败",null); } }
-
package com.model.controller; import com.model.pojo.CommonResult; import com.model.pojo.Payment; import com.model.service.PaymentService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * @Description:测试类 * @Author: 张紫韩 * @Crete 2021/9/5 23:28 */ @Controller @Slf4j @RequestMapping("/payment") public class PaymentController { @Resource private PaymentService paymentService; @PostMapping("/create") @ResponseBody public CommonResult create(Payment payment){ Integer result = paymentService.create(payment); log.info("插入结果:"+result); if (result>0){ return new CommonResult<>(200,"插入成功",result); } return new CommonResult(444,"插入失败",null); } @GetMapping("/get/{id}") @ResponseBody public CommonResult getPaymentById(@PathVariable("id")Long id){ Payment payment = paymentService.getPaymentById(id); log.info("插入结果:"+payment.toString()); if (payment!=null){ return new CommonResult(200,"查询成功",payment); } return new CommonResult(444,"查询失败",null); } }
-
-
-