์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[71] 230410 ๋๊ธฐ์, ๋น๋๊ธฐ์, AJAX, Spring: ๊ฒ์ํ ๋๊ธ [K-๋์งํธ ํธ๋ ์ด๋ 71์ผ] ๋ณธ๋ฌธ
[71] 230410 ๋๊ธฐ์, ๋น๋๊ธฐ์, AJAX, Spring: ๊ฒ์ํ ๋๊ธ [K-๋์งํธ ํธ๋ ์ด๋ 71์ผ]
yjyuwisely 2023. 4. 10. 09:502304010 Mon 71st class
์ฐธ๊ณ : ๋๊ธฐ์ vs ๋น๋๊ธฐ์
https://dev-coco.tistory.com/46
https://sudo-minz.tistory.com/21
์ฐธ๊ณ : ajax
https://azderica.github.io/00-javascript-ajax/
์น ๋ธ๋ผ์ฐ์ → controller → .jsp(ํด๋น ํ๋ฉด์ผ๋ก ์ด๋)
๋๊ธฐ์ ํต์ ๋ฐฉ์
: ๊ธฐ์น์ ๊ฒฐ์ด ์๋ค. (์์)
ex) ์นดํ: ์ฃผ๋ฌธํ ํ์ ์ปคํผ๊ฐ ๋์ฌ๋๊น์ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์
ํ์๊ฐ์
1)
์น๋ธ๋ผ์ฐ์ → MemberController(controller) → Member.jsp(ํ์๊ฐ์
ํ๋ฉด์ผ๋ก ์ด๋)
ํ์๊ฐ์
๋ฒํผ์ ํด๋ฆญ
2)
์น๋ธ๋ผ์ฐ์ → controller → model(ํ์๊ฐ์
์ ๋ณด ์์ง) → service <=> mapper(dao) <=> db
์น๋ธ๋ผ์ฐ์ <=> MemberController(controller) <=> MemberVO(model)(ํ์๊ฐ์
์ ๋ณด ์์ง) → MemberService(service) <=> MemberMapper(mapper(dao)) → Member Table insert <=> db
MemberVO (model) (ํ์๊ฐ์ ์ ๋ณด ์์ง) |
MemberVO (model) |
MemberVO (model) |
MemberVO (model) |
|||||
์น๋ธ๋ผ์ฐ์ | -----------> | MemberController (controller) |
-----------> | MemberService (service) |
-----------> | MemberMapper (mapper(dao)) |
-----------> | Member Table insert |
In software, a data access object (DAO) is a pattern that provides an abstract interface to some type of database or other persistence mechanism.
In computer science, a value object is a small object that represents a simple entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object.
๋ก๊ทธ์ธ
1)
์น๋ธ๋ผ์ฐ์ → MemberController(controller) → Login.jsp(๋ก๊ทธ์ธ ํ๋ฉด์ผ๋ก ์ด๋)
๋ก๊ทธ์ธ ๋ฒํผ์ ํด๋ฆญ
2)
์น๋ธ๋ผ์ฐ์ → controller → model(ํ์๊ฐ์
์ ๋ณด ์์ง) → service <=> mapper(dao) <=> db
์น๋ธ๋ผ์ฐ์ <=> MemberController(controller) <=> MemberVO(model)(ํ์๊ฐ์
์ ๋ณด ์์ง) → MemberService(service) <=> MemberMapper(mapper(dao)) → Member Table insert <=> db
MemberVO (model) (ํ์๊ฐ์ ์ ๋ณด ์์ง) |
MemberVO (model) |
MemberVO (model) |
MemberVO (model) |
|||||
์น๋ธ๋ผ์ฐ์ | <=====> | MemberController (controller) |
<=====> | MemberService (service) |
<=====> | MemberMapper (mapper(dao)) |
<=====> | Member Table |
๋น๋๊ธฐ์ ํต์ ๋ฐฉ์ (ajax)
: ex) ์นดํ: ์ฃผ๋ฌธํ ํ์ ์ง๋๋ฒจ์ด ์ธ๋ฆฌ๋ฉด ์ปคํผ๋ฅผ ๊ฐ์ง๋ฌ ์ค์ธ์!
Ajax is a set of web development techniques that uses various web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behaviour of the existing page.
.jsp์ ๋ณด๋ด๋ ๋๊ธฐ์๊ณผ๋ ๋ฌ๋ฆฌ,
๋น๋๊ธฐ์์ ์น ๋ธ๋ผ์ฐ์ ํํ
๋ฐ์ดํฐ๋ฅผ ์ค๋ค.
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers.
Spring Framework์ ๊ธฐ๋ณธ์ ์ธ ์ธ์ด๋ ์๋ฐ์ด๋ค.
ํ์ง๋ง ๋น๋๊ธฐ์์ ๋ฐ์ดํฐํ์
์ด javascript ๋๋ xml์ด ์ฃผ๋ก ์ธ์ด์ด๋ค.
Spring Framework์์ javascript ํ์
๋๋ xml์ ๋ํ ์ธ์์ด pom.xml์์ ํ์ํ๋ค.
javascript ํ์
๋๋ xml์ ๋ํ ์ธ์์ ํ์ํ jar ํ์ผ์ ๋ค์ด๋ก๋ํ๋ค.
the simplest way to parse JSON with Jackson.
jackson-databind(javascriptํ์
)
jackson-dataformat-xml(xmlํ์
)์ pom.xml์ ์ถ๊ฐํ๋ค.
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.6</version>
</dependency>
๊ฒ์ํ์ ๋๊ธ์ ๋น๋๊ธฐ์์ผ๋ก ๋ง๋ ๋ค.
AJAX๋ jQuery์ ์ผ์ข
์ด๋ค.
reply from reply.js and ReplyVO from ReplyController.java
detail.jsp
<div id="chat">
<ul id="replyUL">
</ul>
</div>
reply.js
function list(param){// listํจ์ ์ ์ธ ์์
//alert(bno);
var bno = param.bno;
var page = param.page;
console.log(bno)
console.log(page)
$.getJSON("/replies/"+bno+"/"+page+".json",function(data){
console.log(data.replycnt)
console.log(data.list)
var str="";
for(var i=0;i<data.list.length;i++){
str+="<li>"+data.list[i].id+"</li>"
str+="<li><textarea id='replycontent"+data.list[i].rno+"'>"+data.list[i].reply+"</textarea></li>"
str+="<li>"
str+="<input class='update' type='button' value='์์ ' data-rno="+data.list[i].rno+">"
str+="<input class='remove' type='button' value='์ญ์ ' data-rno="+data.list[i].rno+">"
str+="</li>"
}
$("#replyUL").html(str);
showReplyPage(data.replycnt,page);
});
}// listํจ์ ์ ์ธ ๋
์์ค๋ฅผ ๋ถ์ํ๋ค. ์์ค๋ฅผ ๋ถ์ํ๋ ๊ฒ์ด ๋จผ์ ๋ค. MVC, DB์ ์ด๋ป๊ฒ ๋ฐ์ดํฐ๋ฅผ ๋์ง๊ณ ์๋์ง
detail.jsp
<div><label>๋๊ธ</label></div>
<div>
<textarea rows="5" cols="50" id="reply"></textarea>
</div>
<div>
reply.js
// ๋๊ธ ์ฐ๊ธฐ๋ฒํผ์ ํด๋ฆญํ๋ฉด
$("#add").on("click",function(){
// ๋๊ธ์ฐ๊ธฐ ๋ฒํผ์ ํด๋ฆญํ์ ๋น์์ ๋๊ธ๋ด์ฉ์ ๊ฐ์ ธ์ฌ๋ ค๋ฉด $("#add").on("click",function(){ ์๋์ ์ ์ธ
var replyValue=$("#reply").val();
var idValue="abcd1";
// ๋๊ธ์ฐ๊ธฐ๋ฅผ ํ๊ธฐ ์ํ ํจ์ ํธ์ถ
add({bno:bnoValue,reply:replyValue,id:idValue});
})
์ ์ผ ํ๋จ์ ์ฝ๋
// ๋๊ธ ์ฐ๊ธฐ๋ฅผ ํ๊ธฐ ์ํ ํจ์ ์ ์ธ
function add(reply){ // addํจ์ ์ ์ธ ์์
console.log(reply);
$.ajax({
type:"post", // method๋ฐฉ์(get, post, put, delete)
url:"/replies/new",
data:JSON.stringify(reply),
// contentType : ajax -> controller๋ก ๋ฐ์ดํฐ ์ ์ก ์ ํ์
// (contentType์ ์๋ตํ๋ฉด web Browerํํ
์์)
contentType:"application/json; charset=utf-8",
success:function(result){
if(result=="success"){
alert("๋๊ธ์ฐ๊ธฐ ์ฑ๊ณต")
list(reply.bno)
}
}
})
} // addํจ์ ์ ์ธ ๋