스프링

 

 

 

 

class UserController

package net.slipp.web;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import net.slipp.domain.User;
import net.slipp.domain.UserRepository;

@Controller
@RequestMapping("/users")
public class UserController {
	
	private static final Logger log = LoggerFactory.getLogger(UserController.class);
	
	
	@Autowired
	private UserRepository userRepository;
	
	
	@GetMapping("/form")
	public String form(){
		return "/user/form";
	}
		
	@PostMapping("")
	public String create(User user){
		log.info("create   : {}", user.toString()); 
		// jpa h2 로 자동으로 인클로드 된다.
		userRepository.save(user);
		return "redirect:/users";
	}
	
	@GetMapping("")
	public String list(Model model){
		// userRepository.findAll() 목록 가져오기
		model.addAttribute("users", userRepository.findAll());
		return "/user/list";
	}
	
	
	@GetMapping("/{id}/form")
	public String updateForm(@PathVariable Long id, Model model){
		User user =userRepository.findOne(id);
		model.addAttribute("user",user);
		return "/user/updateform";
	}
	
}




 

 

updateform.html

{{> include/header}}
{{> include/navigation}}

<div class="container" id="main">
   <div class="col-md-6 col-md-offset-3">
      <div class="panel panel-default content-main">
          
          {{#user}}
          <form name="question" method="post" action="/users">
              <div class="form-group">
                  <label for="userId">사용자 아이디</label>
                  <input class="form-control" id="userId" name="userId" value="{{userId}}">
              </div>
              <div class="form-group">
                  <label for="password">비밀번호</label>
                  <input type="password" class="form-control" id="password" name="password"value="{{password}}">
              </div>
              <div class="form-group">
                  <label for="name">이름</label>
                  <input class="form-control" id="name" name="name" value="{{name}}">
              </div>
              <div class="form-group">
                  <label for="email">이메일</label>
                  <input type="email" class="form-control" id="email" name="email" value="{{email}}">
              </div>
              <button type="submit" class="btn btn-success clearfix pull-right">회원가입</button>
              <div class="clearfix" />
          </form>
          {{/user}}
        </div>
    </div>
</div>

{{> include/footer}}

 

 

 

navigation.html

			<div class="collapse navbar-collapse" id="navbar-collapse2">
				<ul class="nav navbar-nav navbar-right">
					<li class="active"><a href="../index.html">Posts</a></li>
					<li><a href="../user/login.html" role="button">로그인</a></li>
					<li><a href="/users/form" role="button">회원가입</a></li>
					<li><a href="#" role="button">로그아웃</a></li>
					{{#id}}
					<li><a href="/users/{{id}}/form" role="button">개인정보수정</a></li>
					{{/id}}
				</ul>
			</div>

 

 

 

 

 

 

 

 

spring

 

about author

PHRASE

Level 60  머나먼나라

뒷집 마당 벌어진 데 솔뿌리 걱정한다 , 쓸데없이 남의 걱정을 하는 것을 비유하여 이르는 말.

댓글 ( 4)

댓글 남기기

작성