본문 바로가기

SpringFramework/기타

ajax로 값 출력하기

pom.xml

<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-core</artifactId>
	<version>2.7.3</version>
</dependency>
<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-databind</artifactId>
	<version>2.7.3</version>
</dependency>

Controller

@RequestMapping(value="/replies/all/{bno}", method = RequestMethod.GET)
public ResponseEntity<List<ReplyDTO>> list(@PathVariable("bno") int bno){
	ResponseEntity<List<ReplyDTO>> entity = null;
	try {
		entity = new ResponseEntity<>(service.list(bno), HttpStatus.OK);
	} catch (Exception e) {
		e.printStackTrace();
		entity = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
	}
	return entity;
}

jsp파일

var bno = 73786;
$.getJSON("/replies/all/" + bno, function(data){
	var str = "";
	$(data).each(
		function(){
			str += "<li data-rno='" + this.rno + "' class='replyLi'>" + this.rno + " : " + this.replytext + "</li>";
		}	
	);
	$("#replices").html(str);
});


'SpringFramework > 기타' 카테고리의 다른 글

개발시 참고자료  (0) 2020.04.02
IP정보 가져오기  (0) 2018.10.21