home2 ๊ฒŒ์‹œํŒ Spring ๊ฒŒ์‹œํŒ ๋Œ“๊ธ€๊ธฐ๋Šฅ2

๋Œ“๊ธ€๊ธฐ๋Šฅ2

  • ์ด ์ฃผ์ œ์—๋Š” 4๊ฐœ ๋‹ต๋ณ€, 2๋ช… ์ฐธ์—ฌ๊ฐ€ ์žˆ์œผ๋ฉฐ ๋ฌธ๋ฏผํ˜๊ฐ€ 2 ๋…„ ์ „์— ์ „์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์—…๋ฐ์ดํŠธํ–ˆ์Šต๋‹ˆ๋‹ค.
5 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 5 ๊นŒ์ง€ (์ด 5 ์ค‘์—์„œ)
  • ๊ธ€์“ด์ด
    ๊ธ€
  • #129568

    ๋ฌธ๋ฏผํ˜
    ์ฐธ๊ฐ€์ž
    package practice.semo.Comment;
    import lombok.RequiredArgsConstructor;
    import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
    import org.springframework.security.access.prepost.PreAuthorize;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import practice.semo.Member.CustomUsers;
    @Controller
    @RequiredArgsConstructor
    public class CommentController {
        private final CommentRepository commentRepository;
        //@PreAuthorize()
        @PostMapping("/comment")
        String postComment(@RequestParam String content,@RequestParam Long parent, Authentication auth){
            CustomUsers user = (CustomUsers)auth.getPrincipal();
            var data = new Comment();
            data.setContent(content);
            data.setUsername(user.getUsername());
            data.setParentId(parent);
            commentRepository.save(data);
            return"redirect:/list";
        }
    }
    
    ์—์„œ getPrincipal();๊ฐ€ ๋นจ๊ฐ„์ค„๋กœ ๊ทธ์–ด์ง€๊ณ , ์„ค์ •์ด ์•ˆ๋ฉ๋‹ˆ๋‹ค.
    
    #129569

    ๋ฌธ๋ฏผํ˜
    ์ฐธ๊ฐ€์ž
    ์Šคํฌ๋ฆฐ์ƒท(40)
    #129570

    ๋ฌธ๋ฏผํ˜
    ์ฐธ๊ฐ€์ž
    ์Šคํฌ๋ฆฐ์ƒท(40)
    #129590

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    Authentication์„ importํ•  ๋•Œ spring security ์–ด์ฉŒ๊ตฌ์—์„œ import ํ•ด์˜ต์‹œ๋‹ค
    #129607

    ๋ฌธ๋ฏผํ˜
    ์ฐธ๊ฐ€์ž
    ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค
5 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 5 ๊นŒ์ง€ (์ด 5 ์ค‘์—์„œ)
  • ๋‹ต๋ณ€์€ ๋กœ๊ทธ์ธ ํ›„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

About

ํ˜„์žฌ ์›” 700๋ช… ์‹ ๊ทœ์ˆ˜๊ฐ•์ค‘์ž…๋‹ˆ๋‹ค.

  (09:00~20:00) ๋น ๋ฅธ ์ƒ๋‹ด์€ ์นดํ†ก ํ”Œ๋Ÿฌ์Šค์นœ๊ตฌ ์ฝ”๋”ฉ์• ํ”Œ (๋งํฌ)
  admin@codingapple.com
  ์ด์šฉ์•ฝ๊ด€, ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ
โ“’ Codingapple, ๊ฐ•์˜ ์˜ˆ์ œ, ์˜์ƒ ๋ณต์ œ ๊ธˆ์ง€
top

ยฉ Codingapple, All rights reserved. ์Šˆํผ๋กœ์ผ“ ์—๋“€์ผ€์ด์…˜ / ์„œ์šธํŠน๋ณ„์‹œ ๊ฐ•๋™๊ตฌ ๊ณ ๋•๋กœ 19๊ธธ 30 / ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ: 212-26-14752 ์˜จ๋ผ์ธ ๊ต์œกํ•™์›์—… / ํ†ต์‹ ํŒ๋งค์—…์‹ ๊ณ : ์ œ 2017-์„œ์šธ๊ฐ•๋™-0002 ํ˜ธ / ๊ฐœ์ธ์ •๋ณด๊ด€๋ฆฌ์ž: ๋ฐ•์ข…ํ  / ๋Œ€ํ‘œ์ž๋ช…: ๋ฐ•ํ•ด์œค