반응형

 

프로젝트명 마우스 우클릭 -> Properties -> Web Project Settings의
Context root 확인합니다
똑같이 맞춰줘야 경로가 제대로 반영됩니다.

반응형
반응형

JAVA -

List<Map<String, Object>> excelList = new ArrayList<Map<String,Object>>();

excelList = testService.selectList(testVo);

 

List<Object> titleList = new ArrayList<Object>();

 

titleList.add("순위" );

titleList.add("순위2" );

titleList.add("순위3" );

titleList.add("순위4" );

titleList.add("순위5" );

titleList.add("순위6" );

titleList.add("순위7" );

 

List<Object> dataList = new ArrayList<Object>();

 

for(int i = 0; excelList .size(); i++;)

{

    List<Object> subList = new ArrayList<Object>();' 

    subList .add(excelList.get(i).get("rank1") == null ? "" :  subList .add(excelList.get(i).get("rank1"));

    subList .add(excelList.get(i).get("rank2") == null ? "" :  subList .add(excelList.get(i).get("rank2"));

    subList .add(excelList.get(i).get("rank3") == null ? "" :  subList .add(excelList.get(i).get("rank3"));

    subList .add(excelList.get(i).get("rank4") == null ? "" :  subList .add(excelList.get(i).get("rank4"));

    subList .add(excelList.get(i).get("rank5") == null ? "" :  subList .add(excelList.get(i).get("rank5"));

    subList .add(excelList.get(i).get("rank6") == null ? "" :  subList .add(excelList.get(i).get("rank6"));

    subList .add(excelList.get(i).get("rank7") == null ? "" :  subList .add(excelList.get(i).get("rank7"));

 

    dataList .add(subList);

}

 

model.put("titleList ",titleList )

model.put("list",dataList)

model.put("name","rank")

model.put("sheetName","순위")

return "excelView";

 

반응형
반응형

JAVA 에서 String 형의 경우 아래와 같이 자릿수를 구할수 있다.




String a = "abced";


System.out.println("길이>>"+a.length);




위와 같은 코드에서는 아래의 결과가 나올것이다.




길이>>5






String 형의 경우 length 함수를 지원하지만, int 형의경우는 길이 함수가 없다. 이럴경우에는 수학적 함수를 사용하여야 한다.




int a = 1571;


int length = (int)(Math.log10(a)+1);


System.out.println("길이>>"+a);




결과는 아래와 같이 나올 것이다.




길이>>4


반응형
반응형

split는 문자열을 나누는 메서드다.

String 문자열 = "가:나:다:가나다";
String[] 나눈배열 = 문자열.split(":");
//나눈배열 : {"가", "나", "다", "가나다"}
System.out.println(나눈배열[0]);
//결과 : 가
System.out.println(나눈배열[나눈배열.length-1]);
//결과 : 가나다

그런데 아래처럼 쓰면 작동을 안 한다.

String 문자열 = "가.나.다.가나다";
String[] 나눈배열 = 문자열.split(".");

이렇게 써야 한다.

String 문자열 = "가.나.다.가나다";
String[] 나눈배열 = 문자열.split("\\.");

그래야 작동한다.

이건 split의 인자로 들어가는 String 토큰이 regex 정규식이기 때문이다. 정규식에서 .은 무작위의 한 글자를 의미한다. 그러면 모든 문자가 토큰이 되기 때문에 배열에 남는 게 없게 되는 것이다.

따라서 이스케이프 문자를 앞에 붙여 줘야 한다. 그런데 String 안에 이스케이프 문자인 \를 써 주려면 \\라고 써 줘야 한다. 따라서 \\라고 쓰는 것이다. 그래서 \\.이라고 쓰면 정규식 쪽에서는 \.라고 인식을 하고 실제 .을 찾게 되는 것이다.

아악… 머리아프다. 여튼 기억하라. 기호를 써서 split를 쓸 때 뭔가 작동을 안 하면 \\을 붙여 보라.

참, 그냥 \라고만 붙여야 하는 것도 있는데, 아래 애들이다.

\b \t \n \f \r \" \' \\

참고하면 될 것이다.

출처 : https://mytory.net/archives/285

반응형
반응형

Table 구조 배열 가로 형식 출력(피벗) 알고리즘


레코드 수를 n개로 고정하고, 총 레코드 n 건수만큼 동적으로 가로 추출
예) 21(총 건수) / 
5(레코드 수) = 5개의 필드 [ 4(몫) + 1(나머지 > 0) ]


public static void main(String arr[]){
         
int[] numArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                        13, 14, 15, 16, 17, 18, 19, 20, 21};
  int cnt = 0; // 첫 시작값 정의
       int fixedNum = 5; // 고정 레코드 수
    StringBuffer sb = new StringBuffer();
         
  for(int i=0; i<fixedNum; i++){
      sb.append("<tr>"); // 고정 사이즈 n번 <tr>루프
    for(int j=cnt; j<numArr.length; j++){
             /* 추출된 갯수만큼 <td>별 n개 단위의 값을 추출 */
          sb.append("<td>");
          sb.append(numArr[j]);
         sb.append("</td>");
           j = j+(fixedNum-1);
            }
            cnt = i+1; // j의 시작값 위치를 지정 <tr><td>1</td>
            sb.append("</tr>"); // 고정 사이즈 5번 만큼 닫기 루프
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
 
/**
# 출력값
<tr><td>1</td><td>6</td><td>11</td><td>16</td><td>21</td></tr>
<tr><td>2</td><td>7</td><td>12</td><td>17</td></tr>
<tr><td>3</td><td>8</td><td>13</td><td>18</td></tr>
<tr><td>4</td><td>9</td><td>14</td><td>19</td></tr>
<tr><td>5</td><td>10</td><td>15</td><td>20</td></tr>
 */

출처 : http://develop.sunshiny.co.kr/category/8

반응형
반응형

※ JAVA 배열 내에 중복값 제거하기/출력하기


import java.util.TreeSet;

import java.util.Iterator;


TreeSet 중복값을 제거해주고 정렬해줍니다

int [] arr = {1,1,1,2,3,4,5,6};

TreeSet t = new TreeSet();

            for(int i=0; i< arr.length; i++)

            {

                t.add(arr[i]);

            }

            Iterator it = t.iterator();

            int x = 0;

            while(it.hasNext())

            {

                System.out.println(it.next());


            }

결과값은 1,2,3,4,5,6 으로 나오게 됩니다


반응형
반응형
String[] test = {"1","2","3","1","2"};
System.out.println("before length=" + test.length);
 
test = new HashSet<String>
(Arrays.asList(test)).toArray(new String[0]);
System.out.println("after length=" + test.length);
 
for(String s:test){
    System.out.println(s);            
}
 
/* result 
before length=5
after length=3
1
2
3

*/


반응형
반응형

JAVA 형변환 종류들입니다

int to String



String to int



double to String



long to String



float to String



String to double



String to long



String to float



decimal to binary



decimal to hexadecimal




hexadecimal(String) to int



ASCII Code to String



Integer to ASCII Code



Integer to boolean



boolean to Integer



출처 : http://theeye.pe.kr/archives/457

반응형
반응형

SimpleMagic  example 입니다

SimpleMagic - Simple Magic Content and Mime Type Detection Java Package

Here's a quick "magic" number package that I whipped up which allows content-type (mime-type) determination from files and byte arrays. It makes use of the magic(5) Unix content-type files to implement the same functionality as the Unix file(1) command in Java which detects the contents of a file. It uses either internal config files or can read /etc/magic/usr/share/file/magic, or other magic(5) files and determine file content from FileInputStream, or byte[].

Simple Code Sample

The following is a quick code sample to help you get started using the library for mime-type detection.

// create a magic utility using the internal magic file
ContentInfoUtil util = new ContentInfoUtil();
// if you want to use a different config file(s), you can load them by hand:
// ContentInfoUtil util = new ContentInfoUtil("/etc/magic");
...
ContentInfo info = util.findMatch("/tmp/upload.tmp");
// or
ContentInfo info = util.findMatch(inputStream);
// or
ContentInfo info = util.findMatch(contentByteArray);
// display content type information
if (info == null) {
   System.out.println("Unknown content-type");
} else {
   // other information in ContentInfo type
   System.out.println("Content-type is: " + info.getName());
}

Free Spam Protection   Eggnog Recipe   Android ORM   Simple Java Magic   JMX using HTTP   OAuth 2.0 Simple Example   Great Eggnog Recipe   Christopher Randolph  


다운

링크 : https://github.com/j256/simplemagic

반응형

+ Recent posts