Java后端接口编写流程-LMLPHP


Java后端接口编写流程

实现逻辑流程

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("merchant_mcc")
public class MerchantMcc {
    /**
     * null | merchant_mcc.id | @mbg.generated
     */
    @ApiModelProperty("null")
    @TableId
    private Long id;

    /**
     * MCC字段Code | merchant_mcc.code | @mbg.generated
     */
    @ApiModelProperty("MCC字段Code")
    private String code;

    /**
     * MCC字段Description | merchant_mcc.description | @mbg.generated
     */
    @ApiModelProperty("MCC字段Description")
    private String description;
}
package com.wei.gen.po;

public class MerchantMccCol {

	public static final String ID = "id";

	public static final String CODE = "code";

	public static final String DESCRIPTION = "description";

}
public interface MerchantMccRepo extends IService<MerchantMcc> {

    /**
     * MCC 根据Code查询Description
     *
     * @param queryWrapper
     * @return
     */
    MerchantMcc selectOne(QueryWrapper<MerchantMcc> queryWrapper);

}
@Slf4j
@Repository
public class MerchantMccRepoImpl extends ServiceImpl<MerchantMccMapper, MerchantMcc> implements MerchantMccRepo {

    private final MerchantMccMapper merchantMccMapper;

    public MerchantMccRepoImpl(MerchantMccMapper merchantMccMapper) {
        this.merchantMccMapper = merchantMccMapper;
    }

    @Override
    public MerchantMcc selectOne(QueryWrapper<MerchantMcc> queryWrapper) {
        return merchantMccMapper.selectOne(queryWrapper);
    }
}
@Mapper
public interface MerchantMccMapper extends BaseMapper<MerchantMcc> {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table merchant_mcc
     *
     * @mbg.generated
     */
    MerchantMcc selectByPrimaryKey(Long id);
}
<?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.wei.gen.dao.MerchantMccMapper">
  
</mapper>
 /**
     * MCC 根据Code查询Description
     */
    public String getDescriptionByCode(String code) {
        if (code == null || code.isEmpty()){
            throw new ManageException("Code不能为空");
        }

        MerchantMcc merchantMcc = merchantMccRepo.selectOne(new QueryWrapper<MerchantMcc>().eq("code", code));

        if (merchantMcc == null) {
            throw new ManageException("Code不存在");
        }
        return merchantMcc.getDescription();
    }
@RestController
@Slf4j
@RequestMapping("common")
public class SystemCommonEndpoint {
    
    @Resource
    private CommonService commonService;

    /**
     * MCC 根据Code查询Description
     */
    @GetMapping("/search")
    @ApiOperation("MCC根据Code查询Description")
    public Result<String> searchDescription(@RequestParam("code") String code) {
        String description = commonService.getDescriptionByCode(code);
        return Result.succ(description);
    }
}


Java后端接口编写流程-LMLPHP

09-30 23:36