728x90
main.jsp(url을 같은 곳으로 통일)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#get").on("click", function(){
$.ajax({
type: "get",
url: "board",
dataType: "text",
success:
function(data, status, xhr){
console.log(data, "success")
},
error:
function(xhr, status, error){
console.log(error, "fail")
}
})
})
$("#post").on("click", function(){
$.ajax({
type: "post",
url: "board",
dataType: "text",
success:
function(data, status, xhr){
console.log(data, "success")
},
error:
function(xhr, status, error){
console.log(error, "fail")
}
})
})
$("#delete").on("click", function(){
$.ajax({
type: "delete",
url: "board",
dataType: "text",
success:
function(data, status, xhr){
console.log(data, "success")
},
error:
function(xhr, status, error){
console.log(error, "fail")
}
})
})
$("#put").on("click", function(){
$.ajax({
type: "put",
url: "board",
dataType: "text",
success:
function(data, status, xhr){
console.log(data, "success")
},
error:
function(xhr, status, error){
console.log(error, "fail")
}
})
})
})
</script>
</head>
<body>
main<br>
<img src="image/a.jpg" width="100" height="100"><br>
<input type="button" value="get" id="get">
<input type="button" value="post" id="post">
<input type="button" value="delete" id="delete">
<input type="button" value="put" id="put">
</body>
</html>
Controller(method와 함수명의 차별화)
package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TestController {
@RequestMapping(value= "/board", method = RequestMethod.GET)
public String get() {
System.out.println("GET");
return "main";
}
@RequestMapping(value= "/board", method = RequestMethod.POST)
public String post() {
System.out.println("POST");
return "main";
}
@RequestMapping(value= "/board", method = RequestMethod.DELETE)
public String delete() {
System.out.println("DELETE");
return "main";
}
@RequestMapping(value= "/board", method = RequestMethod.PUT)
public String put() {
System.out.println("PUT");
return "main";
}
}
'단순 코드 기록 > Spring' 카테고리의 다른 글
Spring_myBatis_selectAll (0) | 2024.02.15 |
---|---|
Spring_myBatis (0) | 2024.02.15 |
Spring_Context주소 (0) | 2024.02.15 |
Spring_JsonIgnore&Default (0) | 2024.02.15 |
Spring_Ajax (0) | 2024.02.15 |