将字符串转为数组并已JSON形式返回前台

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26975307/article/details/80907272
 private List<String> requirement;
	//在实体类中增加一个属性,用于接收不在数据库中的字段
   	public List<String> getRequirement(){
   		List<String> list = new ArrayList<String>();
   		//判断是否有多余空格["","A","B"]
   		if(description != null && description.length() > 0){
   			String[] split = description.split(" ");
   			for (String str : split) {
   				if( !str.equals("") ){
   					list.add(str);
   				}
   			}
   		}
   		return list;
   	}

猜你喜欢

转载自blog.csdn.net/qq_26975307/article/details/80907272