Java tutorial
/** * Copyright © 2012-2013 <a href="https://github.com/Dopas/dopas">Dopas</a> All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.aistor.common.utils.excel.fieldtype; import java.util.List; import org.apache.commons.lang.StringUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; import com.google.common.collect.Lists; import com.aistor.common.utils.Collections3; import com.aistor.modules.sys.entity.Role; import com.aistor.modules.sys.service.SystemService; /** * ? * @author Zaric * @version 2013-03-10 */ @Service public class RoleListType implements ApplicationContextAware { private static SystemService systemService; /** * ? */ public static Object getValue(String val) { List<Role> roleList = Lists.newArrayList(); List<Role> allRoleList = systemService.findAllRole(); for (String s : StringUtils.split(val, ",")) { for (Role e : allRoleList) { if (e.getName().equals(s)) { roleList.add(e); } } } return roleList.size() > 0 ? roleList : null; } /** * */ public static String setValue(Object val) { if (val != null) { @SuppressWarnings("unchecked") List<Role> roleList = (List<Role>) val; return Collections3.extractToString(roleList, "name", ", "); } return ""; } @Override public void setApplicationContext(ApplicationContext applicationContext) { systemService = (SystemService) applicationContext.getBean("systemService"); } }