본문 바로가기

기존카테고리/Spring Tip

파라미터 값 받기와 전달(Command 객체와 VO,



http://localhost:8081/hoho/userInfo?id=this&name=aaaa&tel=010&email=this@daum.net



@Controller

public class HomeController {

// @Autowired

// Command command;

@RequestMapping("userInfo")

public String userInfo(User user){

Command command = new Command();

command.getInfo(user);

return "userInfo";

}

}





package com.spring.hoho;


public class User {

private String id;

private String name;

private String tel;

private String email;

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getTel() {

return tel;

}

public void setTel(String tel) {

this.tel = tel;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

}




package com.spring.hoho;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;



public class Command {

@Autowired

User user;

public void getInfo(User user){

//user = new User();

String id = user.getId();

String name = user.getName();

String tel = user.getTel();

String email = user.getEmail();

System.out.println("id: "+id);

System.out.println("name: "+name);

System.out.println("tel: "+tel);

System.out.println("email: "+email);

}


}






<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>User Info</h2>
Id: ${user.id}<br>
Name: ${user.name}<br>
Tel: ${user.tel}<br>
Email: ${user.email}<br>
</body>
</html>