致自己第一次解决业务问题

#### 目标: 数据库只有前16位码与后16位码字段,客户要求输入32位码作为查询条件 --已完成 ####

思路: 在Controller层将客户端传过来的32位码参数拆分成前16位和后16位,并且根据数据库前 16位与后16位的字段名为传过来的参数加上前缀一并提交给Service层。 #### 问题:

因为参数是封装到Map集合中的,所以需要调用map集合中的方法,获取前端传过来的参数,也就是map中的key

(1) 调用Map的get方法获取到key,拿到key就相当于拿到了value,返回值为一个32位码的字符串

(2) 调用String类型的subString方法,分两次将前16位和后16位码拆分出来

(3) 调用map中的put方法,将前16位和后16位码放入map集合--(注意:前16位和后16位的key要跟实体类对应的属性名称一样)

(4) 将参数传到service层--->Mapper层---->MapperXml文件--->Sql语句根据传过来的参数一一去数据库查,符合条件,返回数据。

代码:

/**
 * @Author LiYong
 * @Date 2021/3/17 9:26
 */
@RestController
@RequestMapping("dataquery/outcigarstat")
public class ManualOutCigarController {

    @Autowired
    private ManualOutCigarService manualOutCigarService;

    @RequestMapping("/getManualOutCigar")
    public Result list(@RequestParam Map<String,Object> params){
        boolean biteCode = params.containsKey("32bitCode");
        //8020751413138523XTYC430301100158
        //8012644524792243 XTYC430301101394
        if (biteCode){
            String code  = (String) params.get("32bitCode");
            String firstLineValue = code.substring(0, 16);
            String secondLineValue = code.substring(16, 32);
            params.put("firstLine",firstLineValue);
            params.put("secondLine",secondLineValue);
        }
        PageUtils page = manualOutCigarService.queryOutCigar(params);
        return Result.ok().putPage(page);
    }

}
原文地址:https://www.cnblogs.com/yong889/p/14552761.html