文章目录
- 关于若依框架对数组的处理方式
- 一、数据表设计
- 二、controller 接口正常对象接收
- 1.controller
- 2.ServiceImpl
- 3.查询数据对时将字符串转回数组返回前端
- 1.ServiceImpl层
提示:以下是本篇文章正文内容,下面案例可供参考
一、数据表设计 二、controller 接口正常对象接收 1.controller代码如下(示例):
@PreAuthorize("@ss.hasPermi('system:notice:addNotice')")
@PostMapping("/addNotice")
public AjaxResult addNotice(@RequestBody SysNotice notice)
{
//分页
startPage();
//默认新增人
notice.setCreateBy(getLoginUser().getUser().getNickName());
//默认浏览量
notice.setSumcontent("0");
return toAjax(noticeService.insertNotice(notice));
}
2.ServiceImpl
代码如下(示例):
@Override
public int insertZxPolicyDeclaration(ZxPolicyDeclaration zxPolicyDeclaration) {
Long[] policy_label = zxPolicyDeclaration.getPolicy_Label();//'所属标签',
if(policy_label != null) {
zxPolicyDeclaration.setPolicyLabel(StringUtils.join(policy_label,","));
}else{
zxPolicyDeclaration.setPolicyLabel("");
}
return zxPolicyDeclarationMapper.insertZxPolicyDeclaration(zxPolicyDeclaration);
}
1.意思就是说我们表中刚开始是默认string的字段
2.我们又添加了一个Long[]类型数组格式的字段。
3.我们接收是用的Long[]类型那个字段接收的,
我们要给他转成字符串也就是string类型的保存到数据库
3.查询数据对时将字符串转回数组返回前端 1.ServiceImpl层
有几个就写几个
代码如下(示例):
@Override
public List selectNoticeWzList(SysNotice notice) {
List sysNoticeList = noticeMapper.selectNoticeWzList(notice);
if (sysNoticeList != null) {
for (SysNotice sysNotice : sysNoticeList) {
if(sysNotice.getLabel_type() !=null){
sysNotice.setLabelTypes(stringToLong(sysNotice.getLabel_type().split(",")));
}
if (sysNotice.getSupport_type() != null) {
sysNotice.setSupportTypes(stringToLong(sysNotice.getSupport_type().split(",")));
}
if(sysNotice.getSupport_way () !=null){
sysNotice.setSupportWays(stringToLong(sysNotice.getSupport_way().split(",")));
}
}
}
//如果等于空测返回
return sysNoticeList;
}
stringToLong调用代码如下
public Long[] stringToLong(String[] strs) {
Long[] longs = new Long[strs.length];
for(int i=0;i
longs[i] = Long.parseLong(strs[i]);
}
return longs;
}



