본문 바로가기
풀스택/React

8-1 react 프로젝트(react eclipse 연동)

by woohyun22 2019. 5. 9.

react와 spring boot 연동 깃은 따로


react만 사용했을 경우 input을 활용한 insert


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
-import React, { Component } from "react";
-//import Clock from "react-live-clock"
-import axios from "axios";
-
-class Add extends Component {
-  constructor(props) {
-    super(props);
-
-    this.state = {};
-    this.handleChange = this.handleChange.bind(this);
-    this.Send = this.Send.bind(this);
-  }
-
-  handleChange = e => {
-    this.setState({
-      [e.target.name]: e.target.value
-    });
-  };
-  handleSubmit = e => {
-    e.preventDefault();
-  };
-
-  Send = async () => {
-    await axios
-      .post("http://localhost:8076/workattitude/new", this.state)
-      .then(response => {
-        console.log(response);
-      })
-      .catch(response => {
-        console.log(response);
-      });
-  };
-
-  render() {
-    return (
-      <div classname="container-fluid">
-        <form onSubmit={this.handleChange}>
-          신청 시간 및 날짜 :{" "}
-          {
-            // <Clock
-            //   format={"YYYY 년 MM 월 DD 일 HH:mm:ss"}
-            //   ticking={true}
-            //   timezone={"KR/Pacific"}
-            // />
-          }
-          <br />
-          이름 :{" "}
-          <input
-            placeholder="홍길동"
-            type="text"
-            value={this.state.name}
-            onChange={this.handleChange}
-            name="name"
-          />
-          <br />
-          시작 날짜 :{" "}
-          <input
-            type="date"
-            value={this.state.startDay}
-            onChange={this.handleChange}
-            name="startDay"
-          />
-          끝 날짜 :{" "}
-          <input
-            type="date"
-            value={this.state.endDay}
-            onChange={this.handleChange}
-            name="endDay"
-          />
-          <br />
-          제목 :{" "}
-          <input
-            type="text"
-            value={this.state.title}
-            onChange={this.handleChange}
-            name="title"
-          />
-          <br />
-          근태구분 :{" "}
-          <select
-            name="state"
-            type="text"
-            value={this.state.state}
-            onChange={this.handleChange}
-          >
-            <option value="출장">출장</option>
-            <option value="외근">외근</option>
-            <option value="연차">연차</option>
-            <option value="반차">반차</option>
-            <option value="교육">교육</option>
-          </select>
-          <br />
-          근태 사유 :{" "}
-          <input
-            placeholder=""
-            type="text"
-            value={this.state.content}
-            onChange={this.handleChange}
-            name="content"
-          />
-          <br />
-          <br />
-          <input type="submit" onclick={this.Send()} value="근태 신청" />
-          <div />
-        </form>
-      </div>
-    );
-  }
-}
-
-export default Add;
cs



통신은 axios로 한다. 



handlechange에서 render해온 값들을 넣어주고, handlesubmit에서 실시간으로 업데이트해준다. (넣을때 마다 값이 갱신됨) 

Send에서는 axios 통신으로 해당 url의 api와 통신.


-보충 바인드 해주는 이유


728x90

댓글