Fork me on GitHub

表id关联数据获取至页面,制作下拉框多选进行数据多项获取(字段处理)

 这周完成了一张表单,重点碰到以下问题:

1、freemaker获取年份的type值取year,类型直接为Long,传至后台和获取数据不需要转换;

2、freemaker获取日期type值为date,类型需要转换成时间戳,页面类型String,数据库类型Long,需要在接收数据类中进行类型转换和日期处理;

3、下拉多选的freemaker的关键字是   "isMuilt":true  接收list,显示下拉框可以进行多项选择(下面代码给出解答)

4、类似金额、面积可以输入小数的在页面定义float,数据库表是integer的,需要在中间进行数据处理,可以写一个封装类,将数据乘以100进行处理;

 

 

---------------------------------------

目录:

1、控制类处理

2、freemaker页面处理

3、Request接受数据model处理

4、返回页面部分人员字段处理

5、数据库录入数据显示

 6、页面显示效果

 

------------------------------------------

 

1、控制类中:manager表中保存所有人员数据,另一张groupperson表中只保存部分人员的id。获取部分人员的姓名和id:

 1   /**
 2      * 初始化参数
 3      *
 4      * @param model
 5      */
 6     private void begin(Model model) {
 7 
 8         //商区名称
 9         List<MallInfoResp> mallInfoRespList=this.mallInfoServiceClient.findAll().get();
10         model.addAttribute("mallInfoList",mallInfoRespList);
11         model.addAttribute("mallInfoListMapJson",mallInfoListToMapJson(mallInfoRespList));
12         //项目名称
13         ListData<HouseProjectResp> houseProjectRespListData=this.houseRegisterServiceClient.findProjectList(new HouseProjectQueryReq()).get();
14         model.addAttribute("projectInfoList",houseProjectRespListData.getContent());
15         model.addAttribute("projectInfoListMapJson",projectInfoListTopMapJson(houseProjectRespListData.getContent()));
16         //招商人员信息(获取部分人员的id和姓名)
17         List<InvestmentGroupPersonRealResp> investmentGroupPersonRealRespList =
18                 investmentGroupServiceClient.findAllGroupPerson().get().getContent();
19 
20         List<ManagerInfoResp> managerInfoRespList = new ArrayList<>();//招商人员集合
21 
22         Optional.ofNullable(new HashSet<String>(Optional.ofNullable(investmentGroupPersonRealRespList)
23                 .orElse(Lists.newArrayList()).stream()
24                 .filter(item -> !StringUtil.isEmpty(item.getManagerInfoId()))
25                 .map(item -> item.getManagerInfoId()).collect(Collectors.toList()))
26         ).orElse(new HashSet<String>()).stream()
27                 .forEach(
28                         item -> {
29                             ManagerInfoResp managerInfoResp = managerInfoServiceClient.selectManagerInfoById(item).get();
30                             if (managerInfoResp != null) {
31                                 managerInfoRespList.add(managerInfoResp);
32                             }
33                         }
34                 );
35         model.addAttribute("managerList", managerInfoRespList);
36         model.addAttribute("managerListMapJson", managerListToMapJson(managerInfoRespList));
37     }
38 
39 
40 /**
41      * 商区名称转化成json字符串
42      *
43      * @param respList 入参
44      *
45      * @return success
46      */
47     private String mallInfoListToMapJson(List<MallInfoResp> respList) {
48         Map<String,String> map= Maps.newHashMap();
49         if(respList==null||respList.isEmpty()){
50             return JsonUtils.toJson(map);
51         }
52         for(MallInfoResp resp:respList){
53             map.put(resp.getId(),resp.getName());
54         }
55         return JsonUtils.toJson(map);
56     }
57 
58     /**
59      * 项目名称转化成Json字符串
60      *
61      * @param respListData 入参
62      *
63      * @return success
64      */
65     private String projectInfoListTopMapJson(List<HouseProjectResp> respListData){
66         Map<String,String> map=Maps.newHashMap();
67         if(respListData==null){
68             return JsonUtils.toJson(map);
69         }
70         for(HouseProjectResp resp:respListData){//获取内容
71             map.put(resp.getId(),resp.getProjectName());
72         }
73         return JsonUtils.toJson(map);
74     }
75 
76     /**
77      * 招商人员(业务)转换成Json字符串
78      */
79     private String managerListToMapJson(List<ManagerInfoResp> resps){
80         Map<String,String> map=Maps.newHashMap();
81         if(resps==null){
82             return JsonUtils.toJson(map);
83         }
84         for(ManagerInfoResp resp:resps){
85             map.put(resp.getId(),resp.getRealname());
86         }
87         return JsonUtils.toJson(map);
88     }

 

2、freemaker页面显示下拉,人员选择多选:

 1 <#--新增修改弹框-->
 2     <#assign v_add_form_fields=[
 3     {"text":"年份","name":"beginTime","type":"year","required":true,"title":"请输入年份"},
 4     {"text":"项目","name":"projectId","type":"searchSelect","data":projectInfoList,"key":"id","keyText":"projectName","required":true},
 5     {"text":"商区","name":"mallId","type":"searchSelect","data":mallInfoList,"key":"id","keyText":"name","required":true},
 6     {"text":"招商落位(面积)","name":"investAreaString","type":"float","required":true,"title":"请输入大于零的数目"},
 7     {"text":"回款额度","name":"recieveMoneyString","type":"float","required":true,"title":"请输入大于零的数目"},
 8     {"text":"客户接洽数","name":"negotiateNum","type":"numberText","required":true,"title":"请输入大于零的整数"},
 9     {"text":"招商人员","name":"personList","type":"searchSelect","data":managerList,"key":"id","keyText":"realname","required":true,"isMuilt":true,"isRow":true}
10     ]/>
11     <@right.sys_modal_add_form modelName="${v_model_name}" fields=v_add_form_fields submiturl="${v_controller_name}/save" />

 

3、Request接受数据model(对部分人员多选进行字段处理):

接受的数据按照逗号分隔

1     /**
2      *招商人员列表
3      */
4     private List<String> personList;
5 
6     public String getInvestPerson() {
7         return StringUtils.join(personList,"
8 }

 

4、返回页面部分人员字段处理:

 1     /**
 2      *招商人员列表
 3      */
 4     private List<String> personList;
 5 
 6     public List<String> getPersonList() {
 7         String persons = getInvestPerson();
 8         if (persons != null) {
 9             return Arrays.asList(investPerson.split(","));
10         }
11         return personList;
12     }

 

5、数据库录入数据显示:

 

 6、页面显示效果:

新增:

获取:

 

posted @ 2017-12-15 17:27  sunwengang  阅读(650)  评论(0编辑  收藏