import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerController {
	
	Socket sock = null;
	DataOutputStream dos;
	DataInputStream dis;
	//읽기버퍼
	byte[] 	rbuff = new byte[1024];	
	int 	rbuff_cnt =0;
	//연결된 클라이언트 아이피
	String sip =  null;
	String packet = "";
	private Thread recvQThread;
	
	public ServerController() {
		//서버소켓 생성
		recvQThread = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					ServerSocket serversock = new ServerSocket(8081);
					//무한 루프로 클라이언트의 요청을 반복적으로 처리
					while(true) {
						Socket sock = serversock.accept();
						sip = sock.getInetAddress().toString();
						System.out.println("[클라이언트 IP '" + sip + "' 접속됨 ]");
						
						tcpSockServer_read(sock);
					}
				} catch(IOException e) {
					e.printStackTrace();
				}
			}
		});
		recvQThread.start();
	}
	
	public void tcpSockServer_read(Socket sock) {
		try {
			try {
				// 클라이언트와 문자열 통신을 위한 스트림 생정
				dis = new DataInputStream(sock.getInputStream());
				while(true) {
					//Thread.sleep(1);
					rbuff_cnt = dis.read(rbuff);
					
					int i;
					String data = "";
					for (i = 0; i < rbuff_cnt; i++) {
						data += String.format("0x%02X", rbuff[i]).replace("0x", "");
					}
					System.out.println("data : "+ data);
				}
			} finally {
				dis.close();
				dos.close();
				sock.close();
			}
		} catch(IOException e) {
			System.out.println("클라이언트 IP '" + sip + "' 접속종료");
		}
	}
	
	public static void main(String[] args) {
		new ServerController();
	}
}

'개발 > JAVA' 카테고리의 다른 글

Java 자바 UNIX Timestamp 변환 timestamp to date String  (0) 2023.04.20
byte Array to  (0) 2023.04.20
[Java] Byte Reverse  (0) 2023.04.20
myBatis selectone null 처리  (0) 2017.11.21
Spring VO 객제 복사 하기  (0) 2017.08.04
public String getTimestampToDate(String timestampStr){
    long timestamp = Long.parseLong(timestampStr);
    Date date = new java.util.Date(timestamp*1000L); 
    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
    sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT+9")); 
    String formattedDate = sdf.format(date);
    return formattedDate;
}

출처 : https://aljjabaegi.tistory.com/460#Java_%EC%9E%90%EB%B0%94_UNIX_Timestamp_%EB%B3%80%ED%99%98_timestamp_to_date_String

'개발 > JAVA' 카테고리의 다른 글

[Java] TCP Server Thread로 만들기  (0) 2023.04.20
byte Array to  (0) 2023.04.20
[Java] Byte Reverse  (0) 2023.04.20
myBatis selectone null 처리  (0) 2017.11.21
Spring VO 객제 복사 하기  (0) 2017.08.04
public short byteArrayToShort(byte[] bytes) {
    bytes = reverse(bytes);
    return ByteBuffer.wrap(bytes).getShort();
}

public int byteArrayToInt(byte[] bytes) {
    bytes = reverse(bytes);
    return ByteBuffer.wrap(bytes).getInt();
}

public long byteArrayToLong(byte[] bytes) {
    bytes = reverse(bytes);
    return ByteBuffer.wrap(bytes).getLong();
}

public float byteArrayToFloat(byte[] bytes) {
    bytes = reverse(bytes);
    return ByteBuffer.wrap(bytes).getFloat();
}

public double byteArrayToDouble(byte[] bytes) {
    bytes = reverse(bytes);
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    return buffer.getDouble();
}

public byte[] reverse(byte[] objects) {
    byte[] temp = new byte[objects.length];
    for (int left = 0, right = objects.length - 1; left <= right; left++, right--) {
        temp[left]=objects[right];
        temp[right]=objects[left];
    }
    return temp;
}

'개발 > JAVA' 카테고리의 다른 글

[Java] TCP Server Thread로 만들기  (0) 2023.04.20
Java 자바 UNIX Timestamp 변환 timestamp to date String  (0) 2023.04.20
[Java] Byte Reverse  (0) 2023.04.20
myBatis selectone null 처리  (0) 2017.11.21
Spring VO 객제 복사 하기  (0) 2017.08.04
public byte[] reverse(byte[] objects) {
    byte[] temp = new byte[objects.length];
    for (int left = 0, right = objects.length - 1; left <= right; left++, right--) {
        temp[left]=objects[right];
        temp[right]=objects[left];
    }
    return temp;
}
myBatis에서 selectone으로 검색시 결과값이 없는데 int절에 넣고 싶을때가 있을것이다. int절에 넣을때 nullpointerException 오류가 발생하게 된다.
 
//service
int testCnt = testDAO.selectTestCnt(testVO);
//mapper

//dao
public int selectTestCnt(TestVO testVO) {
	return ((Integer) sqlSession.selectOne(NAMESPACE + "selectTestCnt", testVO)).intValue();
}
service 단에서 nullpointerException 오류 발생 이럴때는..........이렇게 해보세요~~!!!
//int testCnt = testDAO.selectTestCnt(testVO);
//dao
public int selectTestCnt(TestVO testVO) {
	return sqlSession.selectOne(NAMESPACE + "selectTestCnt", testVO;
}
//service
Integer testCnt = testDAO.selectTestCnt(testVO);
testCnt = testCnt == null ? 0 : testCnt;

'개발 > JAVA' 카테고리의 다른 글

byte Array to  (0) 2023.04.20
[Java] Byte Reverse  (0) 2023.04.20
Spring VO 객제 복사 하기  (0) 2017.08.04
java 인코딩 깨질때 [한글 인코딩 오류] 체크  (0) 2017.07.21
Java split 사용법  (0) 2017.04.05

프로그램을 만들다 보면 VO 객체를 복사할 경우가 많이 생기게 된다.


3~4개 정도


그럴 경우 Spring FameWork 에서 포함되어 있는.


BeanUtil.copyProperty("sourceVO", "targetVO') 


으로 사용하면 된다.


주의할 점.)

BeanUtils 는 apache Jakarta Project 로 apache.commons.beanUtils 은 copyProperty("tartget", "source")

이다.


Spring에서 포함 되면서 가공되어진 것으로 보인다. API 필히 확인. ㅋ



출처: http://srue.tistory.com/62 [Srue Story.]

if ( strSearchText != null ) {

String charset[] = {"euc-kr", "ksc5601", "iso-8859-1", "8859_1", "ascii", "utf-8"};

   

for(int k=0; k<charset.length ; k++){

for(int l=0 ; l<charset.length ; l++){

if(k==l){

continue;

}else{ 

out.println(charset[k]+" : "+charset[l]+" :"+new String(strSearchText.getBytes(charset[k]),charset[l])+"<br />");

}

}

}

'개발 > JAVA' 카테고리의 다른 글

myBatis selectone null 처리  (0) 2017.11.21
Spring VO 객제 복사 하기  (0) 2017.08.04
Java split 사용법  (0) 2017.04.05
eclipse에서 대소문자 단축키 세로영역 드래드 방법  (0) 2017.03.27
json vo객체에 list로 받기  (0) 2017.03.15

String text = "홍길동,010-1234-5678,대한민국";
String[] textArr = text .split(",");
배열에 담아서 순서대로 꺼내서 쓰면 끝
String name = textArr[0];
String phone = textArr[1];
String addr = textArr[2];

eclipse에서 대소문자 단축키 입니다.


소문자 변환 : 블럭 지정 후 ctrl + shift + Y


대문자 변환 : 블럭 지정 후 ctrl + shift + X


세로 영역 드래드 방법은

 

shift + alt + A 


드래그 끝내려면  똑같이 한번더 눌러주면 종료됩니다.^^

'개발 > JAVA' 카테고리의 다른 글

myBatis selectone null 처리  (0) 2017.11.21
Spring VO 객제 복사 하기  (0) 2017.08.04
java 인코딩 깨질때 [한글 인코딩 오류] 체크  (0) 2017.07.21
Java split 사용법  (0) 2017.04.05
json vo객체에 list로 받기  (0) 2017.03.15

우선 json을 만드는 방법입니다.

{"mainList":[{"name":"john1","userId":"john11"},{"name":"john2","userId":"john22"}]}

예)

var totData = new Object();

var data = new Object();

var dataList = new Array();

data["name"] = "john1";

data["userId"] = "john11";

dataList.push(data);

var data = new Object();

data["name"] = "john2";

data["userId"] = "john22";

dataList.push(data);

totData["mainList"] = dataList;

console.log(totData);


이런식으로 만들어서

ajax 호출로 던짐 꼭 json 형식이 아니여도 form serialize 방식으로 던져도 되구요

$.ajax({

contentType:'application/json',

dataType : 'json',

data : JSON.stringify(totData),

url : 'test.json', 

type : 'POST',

success:function(data){

}

});


constroll 단에서  받기


@RequestMapping(value = "/test.json", method=RequestMethod.POST)

@ResponseBody

public Result test(Result result, @RequestBody testVO param) throws Exception {

for(testVO str : param.getMainList()) {

System.out.println("name-------------->"+str.getName()); 

System.out.println("userId-------------->"+str.getUserId()); 

}

}


VO 단


public class testVO {

private String name;

private String userId;


private List<testVO> mainList;


public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getUserId() {

return userId;

}

public void setUserId(String userId) {

this.userId = userId;

}

public List<testVO> getMainList() {

return mainList;

}

public void setMainList(List<Wms151002VO> mainList) {

this.mainList = mainList;

}

}


혹시 dhtmlx 를 쓰시는 분은(제가 지금 dhtmlx플젝이라...)

var mainDataList = new Array();

var totData = new Object();

mainGrid.forEachRow(function(id){

var data = new Object();

mainGrid.forEachCell(id, function(cellObj,ind){

var columnName = mainGrid.getColumnId(ind);

var columnValue = mainGrid.cells(id,ind).getValue();

 

data[columnName] = columnValue;

});

mainDataList.push(data);

});

totData["mainList"] = mainDataList;

console.log(JSON.stringify(totData)); 


요런 식으로??ㅎㅎㅎㅎㅎㅎ

+ Recent posts