본문 바로가기
Backend/SpringBoot

Get방식 parameter 넘기기

by YERIEL_염주둥 2020. 5. 26.
728x90

1. 보내는 객체 이름이 member 객체와 같다면

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
  layout:decorator="@{layout/default}">
  
	<th:block layout:fragment="customTitle">
		<title th:text="${title}"></title>
	</th:block>
	
	<th:block layout:fragment="customContents">
		<table border="1">
			<thead>
				<tr>
					<td>아이디</td>
					<td>비밀번호</td>
					<td>권한</td>
					<td>이름</td>
					<td>이메일</td>
					<td>수정</td>
					<td>삭제</td>
				</tr>
			</thead>
			<tbody>
				<tr th:each="m : ${memberList}">
					<td th:text="${m.memberId}"></td>
					<td>[[${m.memberPw}]]</td>
					<td>[[${m.memberLevel}]]</td>
					<td>[[${m.memberName}]]</td>
					<td>[[${m.memberEmail}]]</td>
					<td> 
						<a th:href="@{/modifyMember(memberId=${m.memberId})}"> 수정 </a>
					</td>
					<td>
						<a th:href="@{#}"> 삭제 </a>
					</td>
				</tr>
			</tbody>
		</table>
	</th:block>
	
	<th:block layout:frament="customFooterScript">
	
	</th:block>
	
</html>
package ksmart35.springboot_mybatis.domain;

public class Member {
	private String memberId;
	private String memberPw;
	private String memberName;
	private String memberLevel;
	private String memberEmail;
	public String getMemberId() {
		return memberId;
	}
	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
	public String getMemberPw() {
		return memberPw;
	}
	public void setMemberPw(String memberPw) {
		this.memberPw = memberPw;
	}
	public String getMemberName() {
		return memberName;
	}
	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}
	public String getMemberLevel() {
		return memberLevel;
	}
	public void setMemberLevel(String memberLevel) {
		this.memberLevel = memberLevel;
	}
	public String getMemberEmail() {
		return memberEmail;
	}
	public void setMemberEmail(String memberEmail) {
		this.memberEmail = memberEmail;
	}
	@Override
	public String toString() {
		return "Member [memberId=" + memberId + ", memberPw=" + memberPw + ", memberName=" + memberName
				+ ", memberLevel=" + memberLevel + ", memberEmail=" + memberEmail + "]";
	}
	
}
package ksmart35.springboot_mybatis.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import ksmart35.springboot_mybatis.domain.Member;
import ksmart35.springboot_mybatis.service.MemberService;

@Controller
public class MemberController {
	@Autowired private MemberService memberService;
	
	@GetMapping("/modifyMember")
	public String modifyMember(Model model, Member member ){
		if(member.getMemberId() !=null && !"".equals(member.getMemberId())) {
			System.out.println("memberId : "+ member.getMemberId());
		}else System.out.println("memberId가 null");
		return "index";
	}
	
}

 

2. 보내는 객체 이름이 다를때

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
  layout:decorator="@{layout/default}">
  
	<th:block layout:fragment="customTitle">
		<title th:text="${title}"></title>
	</th:block>
	
	<th:block layout:fragment="customContents">
		<table border="1">
			<thead>
				<tr>
					<td>아이디</td>
					<td>비밀번호</td>
					<td>권한</td>
					<td>이름</td>
					<td>이메일</td>
					<td>수정</td>
					<td>삭제</td>
				</tr>
			</thead>
			<tbody>
				<tr th:each="m : ${memberList}">
					<td th:text="${m.memberId}"></td>
					<td>[[${m.memberPw}]]</td>
					<td>[[${m.memberLevel}]]</td>
					<td>[[${m.memberName}]]</td>
					<td>[[${m.memberEmail}]]</td>
					<td> 
						<a th:href="@{/modifyMember(m_Id=${m.memberId})}"> 수정 </a>
				</td>
					<td>
						<a th:href="@{#}"> 삭제 </a>
					</td>
				</tr>
			</tbody>
		</table>
	</th:block>
	
	<th:block layout:frament="customFooterScript">
	
	</th:block>
	
</html>
package ksmart35.springboot_mybatis.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import ksmart35.springboot_mybatis.domain.Member;
import ksmart35.springboot_mybatis.service.MemberService;

@Controller
public class MemberController {
	@Autowired private MemberService memberService;
	
	@GetMapping("/modifyMember")
	public String modifyMember(Model model, @RequestParam(name = "m_Id", required = false) String m_Id){
		if(m_Id !=null && !"".equals(m_Id)) {
			System.out.println("m_Id : "+ m_Id);
		}else System.out.println("m_Id가 null");
		return "index";
	}
}
반응형

'Backend > SpringBoot' 카테고리의 다른 글

SpringBoot 파일 업로드 & 다운로드 코드 분석  (0) 2020.06.16
Spring Boot 리다이렉트하기  (0) 2020.05.26
Baeldung  (0) 2020.05.26
MyBatis insert  (0) 2020.05.25
thymeleaf utility objects  (0) 2020.05.19

댓글