250x250
Notice
Recent Posts
Recent Comments
«   2024/09   »
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
Tags more
Archives
Today
Total
관리 메뉴

개린이 개발노트

[스프링]Spring Spring Form Tag 스프링 폼태그 본문

스프링Spring

[스프링]Spring Spring Form Tag 스프링 폼태그

개린이9999 2022. 12. 17. 21:55
728x90

스프링폼컨트롤러

package com.jth.exercise.test.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.jth.exercise.test.vo.OrderRequest;

/**
 * 스프링 폼 태그 
 * @author 김상훈
 */
@Controller
public class SpringFormController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(SpringFormController.class);

	/**
	 * 스프링폼 등록화면
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/springform/registerForm")
	public String registerForm(Model model)throws Exception {
		
		LOGGER.info("SpringFormController,registerForm.");
		
		model.addAttribute("orderRequest", new OrderRequest());
		
		return "springform/registerForm";
	}
}

JSP

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>register</title>
</head>
<body>
<h1>Spring Form Tag</h1>
<form:form modelAttribute="orderRequest" method="post" action="springform/register">
<table>
<tr>
	<td>발주요청번호</td>
	<td>
	<form:input path="orderRequestNo"/>
	</td>
</tr>
<tr>
	<td>발주요청일</td>
	<td>
		<form:input path="orderRequestDate"/>
	</td>
</tr>
<tr>
	<td>발주품목</td>
	<td>
		<form:input path="itemNm"/>
	</td>
</tr>
</table>
</form:form>
</body>
</html>

Vo

package com.jth.exercise.test.vo;

public class OrderRequest {
	
	private int orderRequestNo;
	private String orderRequestDate;
	private String itemNm;
	
	
	public int getOrderRequestNo() {
		return orderRequestNo;
	}
	public void setOrderRequestNo(int orderRequestNo) {
		this.orderRequestNo = orderRequestNo;
	}
	public String getOrderRequestDate() {
		return orderRequestDate;
	}
	public void setOrderRequestDate(String orderRequestDate) {
		this.orderRequestDate = orderRequestDate;
	}
	public String getItemNm() {
		return itemNm;
	}
	public void setItemNm(String itemNm) {
		this.itemNm = itemNm;
	}
	
	@Override
	public String toString() {
		return "OrderRequest [orderRequestNo=" + orderRequestNo + ", orderRequestDate=" + orderRequestDate + ", itemNm="
				+ itemNm + "]";
	}
	
}

완성!!

728x90