에서 (쉼표를 사용하여) 드문 값을 찾기 위해이어떻게 행을 비교하고 공통의 가치와 자바
TableA의
Id Town City Country
1 a b c
1 a b d
1 a b e
2 f g h
2 f g i
2 f g j
3 k l m
이가 내 JSP 페이지에서
내가 필요 어떻게 내 테이블 표의 데이터를 표시하십시오. Title
Id Town City Country
1 a b c,d,e
2 f g h,i,j
3 k l m
(TableA에서 ID, 도시, 도시, 국가 선택)을 실행합니다. 그 다음
public List<Place> getAddressChangeView()
{
List <Place> countriesList = new ArrayList < Place>();
List <Object[]> z = query.getResultList();
List<String> countries = new ArrayList String;
String delim ="," ;
Place places = null;
for (Object[] j: z)
{
places = new Place();
int id = ((String) obj[0]);
String town=((String) obj1);
String city=((String) obj[2]);
String country=((String) obj[3]);
if (! id.equals(id1) && ! town.equals(town1) && ! city.equals(city1) && ! country.equals(country1))
{
id1= id;
town1= town;
city1=city;
country1=country;
places.setId(id);
places.setTown(town);
places.setCity(city);
}
countries.add(country);
StringBuilder sb = new StringBuilder();
for (String s: countries)
{
sb.append(s).append(delim);
}
places.setCountry(sb.toString());
countriesList.add(places);
}
return countriesList;
}