
 
 
 
Java后端接口编写流程
 
 
实现逻辑流程
 
 
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("merchant_mcc")
public class MerchantMcc {
    
    @ApiModelProperty("null")
    @TableId
    private Long id;
    
    @ApiModelProperty("MCC字段Code")
    private String code;
    
    @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> {
    
    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> {
    
    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>
 
 
 
    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;
    
    @GetMapping("/search")
    @ApiOperation("MCC根据Code查询Description")
    public Result<String> searchDescription(@RequestParam("code") String code) {
        String description = commonService.getDescriptionByCode(code);
        return Result.succ(description);
    }
}
 
 
 
 
