StudentAdd.js
3.3 KB
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
import React from 'react';
import {post} from 'axios';
class StudentAdd extends React.Component{
constructor(props){
super(props);
this.state={
st_Code:'',
st_Name:'',
st_Id:'',
st_Major:'',
st_Midscore:'',
st_Finalscore:'',
st_Assignscore:'',
st_Attendscore:'',
st_Score:''
}
}
handleFormSubmit = (e) => {
e.preventDefault()
this.addStudent()
.then((response) => {
console.log(response.data);
this.props.stateRefresh();
})
this.setState({
st_Code:'',
st_Name:'',
st_Id:'',
st_Major:'',
st_Midscore:'',
st_Finalscore:'',
st_Assignscore:'',
st_Attendscore:'',
st_Score:''
})
}
handleValueChange = (e) => {
let nextState = {};
nextState[e.target.name]=e.target.value;
this.setState(nextState);
}
addStudent = () =>{
const url ='/api/students';
const formData=new FormData();
formData.append('st_Code',this.state.st_Code);
formData.append('st_Name',this.state.st_Name);
formData.append('st_Id',this.state.st_Id);
formData.append('st_Major',this.state.st_Major);
formData.append('st_Midscore',this.state.st_Midscore);
formData.append('st_Finalscore',this.state.st_Finalscore);
formData.append('st_Assignscore',this.state.st_Assignscore);
formData.append('st_Attendscore',this.state.st_Attendscore);
formData.append('st_Score',this.state.st_Score);
const config = {
headers: {
'content-tupe': 'multipart/form-data'
}
}
return post(url, formData, config);
}
render(){
return(
<form onSubmit={this.handleFormSubmit}>
<h1>학생 추가</h1>
코드 번호 : <input type="text" name="st_Code" value={this.state.st_Code} onChange={this.handleValueChange}/><br/>
이름 : <input type="text" name="st_Name" value={this.state.st_Name} onChange={this.handleValueChange}/><br/>
학번 : <input type="text" name="st_Id" value={this.state.st_Id} onChange={this.handleValueChange}/><br/>
전공 : <input type="text" name="st_Major" value={this.state.st_Major} onChange={this.handleValueChange}/><br/>
중간 점수 : <input type="text" name="st_Midscore" value={this.state.st_Midscore} onChange={this.handleValueChange}/><br/>
기말 점수 : <input type="text" name="st_Finalscore" value={this.state.st_Finalscore} onChange={this.handleValueChange}/><br/>
과제 점수 : <input type="text" name="st_Assignscore" value={this.state.st_Assignscore} onChange={this.handleValueChange}/><br/>
출석 점수 : <input type="text" name="st_Attendscore" value={this.state.st_Attendscore} onChange={this.handleValueChange}/><br/>
학점 : <input type="text" name="st_Score" value={this.state.st_Score} onChange={this.handleValueChange}/><br/>
<button type="submit">추가하기</button>
</form>
)
}
}
export default StudentAdd;