admin/register.html
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
|
<table id="admin" style="width: 80%; height:80%; margin: 0 auto">
<tr style="width: 80%;height: 50px;">
<td rowspan="4">
<img src="https://u5b8t9w6.stackpathcdn.com/wp-content/uploads/2014/12/profile-default-300x242.jpg">
</td>
<td style="height: 20%">
<label>이름</label>
</td>
<td>
<input id="name" type="text" />
</td>
</tr>
<tr style="height: 20%">
<td >
<label>직급</label>
</td>
<td>
<input id="position" type="text" />
</td>
</tr>
<tr style="height: 20%">
<td>
<label>이메일</label>
</td>
<td>
<input id="email" type="text" />
</td>
</tr>
<tr style="height: 20%">
<td>
<label>전화번호</label>
</td>
<td>
<input id="phoneNumber" type="text" />
</td>
</tr>
<tr style="height: 20%">
<td colspan="3">
<input id="admin_register" type="button" value="등록하기" style="width: 200px; height: 100px;font-size: 30px;"/>
<input id="admin_cancel" type="button" value="취소하기" style="width: 200px; height: 100px;margin-left: 50px;font-size: 30px;"/>
</td>
</tr>
</table>
|
cs |
admin/register.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
$('#admin_register').click(e=>{
e.preventDefault()
$.ajax({
url : '/admins',
type : 'post',
data : JSON.stringify({
name : $('#name').val(),
position : $('#position').val(),
email : $('#email').val(),
phoneNumber : $('#phoneNumber').val()
}),
dataType : 'json',
contentType : 'application/json',
success : d => {
location.href = 'access.html'
},
error : (r,x,m)=>{ r.status}
})
})
|
cs |
AdminController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@RestController
@RequestMapping("/admins")
public class AdminController {
@Autowired AdminService adminService;
@PostMapping("")
public Messenger post(@RequestBody Admin admin) {
System.out.println("1. AdminController post "+admin);
adminService.register(admin);
System.out.println("5. AdminController post ");
return Messenger.SUCCESS;
}
|
cs |
AdminServiceImpl.java
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
|
@Service
public class AdminServiceImpl implements AdminService{
@Autowired AdminDao adminDao;
@Override
public void register(Admin admin) {
/*
employNumber, passwd ,name , position, profile, email, phoneNumber, registerDate;
* */
System.out.println("2. AdminServiceImpl register "+admin);
admin.setEmployNumber(createEmployNumber());
admin.setPasswd("1");
admin.setRegisterDate(createCurrentDate());
adminDao.insert(admin);
}
private String createCurrentDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
private String createEmployNumber() {
String startNum = "";
for(int i=0;i < 4;i++) {
startNum += String.valueOf((int)(Math.random()*10));
}
return startNum;
}
|
cs |
AdminDaoImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
@Repository
public class AdminDaoImpl implements AdminDao{
@Override
public void insert(Admin admin) {
System.out.println("3. AdminDaoImpl insert "+admin);
try {
BufferedWriter writer = new BufferedWriter(
new FileWriter(
new File(Data.ADMIN_PATH.toString() + Data.LIST + Data.CSV), true));
writer.write(admin.toString());
writer.newLine();
writer.flush();
System.out.println("4. File input success ");
}catch(Exception e) {
System.out.println(Messenger.FILE_INSERT_ERROR);
}
}
|
cs |
콘솔에 찍힌 내용 확인
해당 경로 확인
저장된 내용 확인
'프로젝트 > 스프링 & 타임리프' 카테고리의 다른 글
35. 쇼핑몰 :: JPA 설정용 Customer.java, CustomerDTO.java, CustomerController.java, CustomerRepository.java (0) | 2020.04.30 |
---|---|
40. 질병관리 :: 관리자 등록 템플릿 register.html (0) | 2020.04.28 |
40. 질병관리 :: 홈 화면 index.html 템플릿 (0) | 2020.04.28 |
40. 질병관리 :: 최초 index.html ※ 템플릿 사용하지 않고 쉽게 시작하기 (0) | 2020.04.17 |
37. 여행 :: 마이바티스 설정 MyBatisConfig.java (0) | 2020.03.24 |