board2controller
package org.lhr.controller;
import org.lhr.DTO.BoardDTO;
import org.lhr.DTO.Criteria;
import org.lhr.DTO.PageDTO;
import org.lhr.service.Board2Service;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.mysql.cj.log.Log;
/*
@Controller
@RequestMapping("/board")
public class Board2Controller {
private static final Logger logger = LoggerFactory.getLogger(Board2Controller.class);
@Autowired
Board2Service bservice;
@RequestMapping(value="/write",method=RequestMethod.GET)
public void boardWrite2() {
}
@RequestMapping(value="/write",method=RequestMethod.POST)
public String boardWrite22(BoardDTO bdto) {
// 작성하기 버튼을 클릭.
bservice.write2(bdto);
return "/board/list";
}*/
/*//페이징하기전 list
@RequestMapping(value="/list",method=RequestMethod.GET)
public void GetList(Model model) {
// 작성하기 버튼을 클릭.
model.addAttribute("list", bservice.list2());
}
@GetMapping("/list")
public void getListPaging(Criteria cri, Model model) {
int total=bservice.getTotal();
logger.info("cri = "+cri);
logger.info("전체건수 = "+total);
model.addAttribute("list", bservice.list2(cri));
model.addAttribute("pageMaker",new PageDTO(cri,total));
}
@GetMapping("/detail")
public void GetDetail2(Model model, @RequestParam("bno") int bno){
model.addAttribute("detail",bservice.detail2(bno));
//detail에 저장했으니까 view에도 detail에 꺼를 가져가야함 detail.title
}
/*
@RequestMapping(value="/update",method=RequestMethod.POST)
public String boardUpdate(BoardDTO bdto) {
bservice.update2(bdto);
return"redirect:/board/list";
}
@RequestMapping(value="/delete",method=RequestMethod.POST)
public String boardDelete(BoardDTO bdto) {
// 삭제하기 버튼을 클릭.
bservice.delete2(bdto);
return"redirect:/board/list";
}*/
/*
@GetMapping("/update") //update 페이지로 가기위한 용도
public void getUpdate(@RequestParam("bno") int bno,Model model) {
model.addAttribute("modify", bservice.detail2(bno));
}
//"redirect:/board/update?bno="+bdto.getBno();
@PostMapping("/update") // 업데이트 기능으로 가기 위한 용도
public String postUpdate(BoardDTO bdto) {
bservice.update2(bdto);
return "redirect:/board/list";
//값을 가져오기 위해서 redirect 뒤에 bdto.getBno()방식 가져올것
//update된 후에 update페이지에 보여줘야하기때문에 값을 가지고 위에 controller로 감
}
@PostMapping("/delete")
public String postDelete(BoardDTO bdto){
// logger.info("삭제되었는가?");
bservice.delete2(bdto);
return "redirect:/board/list";
}
}*/
boardcontroller
package org.lhr.controller;
import org.lhr.DTO.BoardDTO;
import org.lhr.DTO.Criteria;
import org.lhr.DTO.PageDTO;
import org.lhr.service.BoardService;
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.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@RequestMapping(value="/board",method=RequestMethod.GET)
public class BoardController{
private static final Logger Logger = LoggerFactory.getLogger(BoardController.class);
@Autowired
BoardService bservice;
@GetMapping("/write")
public void getWrite() {
}
@PostMapping("/writePost")
public String postWrite(BoardDTO bdto, Model model) {
System.out.println("writePost");
bservice.boardWrite(bdto);
model.addAttribute("result","success");
return "redirect:/board/list";
}
@GetMapping("/list")
public void getListPaging(Criteria cri, Model model) {
int total=bservice.getTotal();
Logger.info("cri = "+cri);
Logger.info("전체건수 = "+total);
model.addAttribute("list", bservice.boardList(cri));
model.addAttribute("pageMaker",new PageDTO(cri,total));
}
@GetMapping("/update")
public void boardUpdate(BoardDTO bdto) {
bservice.boardUpdate(bdto);
Logger.info("/update");
}
@RequestMapping(value="/delete",method=RequestMethod.POST)
public String boardDelete(BoardDTO bdto) {
// 삭제하기 버튼을 클릭.
bservice.boardDelete(bdto);
return"redirect:/board/list";
}
@GetMapping("/detail")
public void GetDetail2(Model model, @RequestParam("bno") int bno){
model.addAttribute("detail",bservice.detail(bno));
//detail에 저장했으니까 view에도 detail에 꺼를 가져가야함 detail.title
}
}
//@Controller
//@RequestMapping("/board")
//public class BoardController {
//@Autowired
//패키지가 다른데에서 클래스를 불러올때 선언해줌
//private BoardService bservice; // private BoardService bservice = new BoardService();
//클래스명
//private static final Logger Logger = LoggerFactory.getLogger(BoardController.class);
//@GetMapping("/update")
//public String GetWrite(Model model) {
//Logger.info("/update");
//String name = "정자바";
// model.addAttribute("name", name);
// return "/board/write"; }
// @GetMapping("/write")
// public String Getwrite(@ModelAttribute("name") String name) {
// Logger.info("게시판 글쓰기");
// return "board/write";
// }
//return 값이 없으면 value값에 .jsp를 붙여서 이동
/*
@PostMapping("/write")
//@RequestMapping(value="/write",method=RequestMethod.POST)
//스프링 프레임워크에 따라서 둘중에 하나 를 사용해야함 4.3 이전인지 아닌지 위 아래는 같은 뜻임
//MultipartFile 파일 타입
//스프링은 view파일이랑 여기 매개변수랑 이름이 같아야함 file의 name값
//이미지업로드는 무조건 post방식으로 가야함
//public void Postupdload(BoardDTO bdto,ArrayList<MultipartFile> files) {
public void Postwrite(BoardDTO bdto) {
bservice.boardInsert(bdto);
}
*/
/*
*
*
@GetMapping("/read")
public void boardRead() {
Logger.info("/read");
}
for(int i = 0; i<file.size();i++) {
Logger.info("업로드 된 파일 이름 = "+files.get(i).getOriginalFilename());
Logger.info("업로드 된 파일 크기 = "+files.get(i).getSize());}
*/
/*files.forEach(file->{
Logger.info("업로드 된 파일 이름 = "+file.getOriginalFilename());
Logger.info("업로드 된 파일 크기 = "+file.getSize());
});*/
//model의 역할은 controller에 있는 데이터를 화면(.jsp)으로 보내는 역할
//데이터를 가지고 화면으로 가라
//foreach 로하면 부조건 0부터 돌아감 배열에서만 사용할 수 잇는 for문
//1에서부터 돌리고싶다? 불가능
//file은 임시 저장소 역할을 함 변수가 하나 더잇는것임 files에서 file로 가져와서 출력해라라는 뜻
/*
@GetMapping("/write")
public void boardWrite() {
Logger.info("/write");
//return "bw3"; //return값을 주려면 파일이름이 return값과 같아야 찾을 수 있음
//return값을 줬을때 폴더안에 view파일이 있으면 return값에 /폴더명 붙여줘야함
}
@RequestMapping(value="/redirect",method=RequestMethod.GET)
public String Redirect(RedirectAttributes rttr) {
rttr.addFlashAttribute("name","정자바");
rttr.addFlashAttribute("age", 10);
return"redirect:/";
}
} */
examcontroller
package org.lhr.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@RequestMapping("/Exam")
public class ExamController {
private static final Logger logger = LoggerFactory.getLogger(ExamController.class);
@RequestMapping(value="/exam01",method=RequestMethod.GET)
public String ex01(RedirectAttributes rttr) {
rttr.addFlashAttribute("name", "김그린");
rttr.addFlashAttribute("age", 58);
rttr.addFlashAttribute("gender", "여자");
return "redirect:/Exam/exam02";
}
@RequestMapping(value="/exam02",method=RequestMethod.GET)
public String exam02() {
return "Exam/ex03";
}
//return값이 없으면 ex03에 .jsp를 붙여서 이동함
@RequestMapping(value="/exam03",method=RequestMethod.GET)
public String exam00(@RequestParam("name") String name,
@RequestParam("age") int age,
@RequestParam("gender") String gender) {
return "Exam/ex02";
}
}
homecontroller
package org.lhr.controller;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
}
lbmcontroller
package org.lhr.controller;
import org.lhr.DTO.LBMboardDTO;
import org.lhr.DTO.LBMmemberDTO;
import org.lhr.service.LBMService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/lbm")
public class LBMController {
@Autowired
LBMService lbmservice;
private static final Logger Logger = LoggerFactory.getLogger(LBMController.class);
@GetMapping("/login")
public void login(){
}
@PostMapping("/login")
public void login2() {
}
@GetMapping("/boardlist")
public void boardlist(Model model){
model.addAttribute("list", lbmservice.boardlist());
}
@GetMapping("/boarddetail")
public void boarddetail(Model model,@RequestParam("bno") int bno){
System.out.println("controller="+lbmservice.boarddetail(bno));
model.addAttribute("detail",lbmservice.boarddetail(bno));
}
@PostMapping("/boarddetail")
public String boarddetail2(@RequestParam("bno") int bno){
return"redirect:/lbm/boardmodify?bno="+bno;
}
@GetMapping("/addmember")
public void addmember2(){
}
@PostMapping("/addmember")
public String addmember(LBMmemberDTO lbmm){
Logger.info("실행됨"+lbmm);
lbmservice.memberinsert(lbmm);
return "/lbm/login";
}
@GetMapping("/boardwrite")
public void boardwrite(){
}
@PostMapping("/boardwrite")
public String boardwrite2(LBMboardDTO lbmb){
lbmservice.boardwrite(lbmb);
return "redirect:/lbm/boardlist";
}
@GetMapping("/boardmodify")
public void boardmodify(@RequestParam("bno")int bno, Model model ) {
model.addAttribute("modify", lbmservice.boarddetail(bno));
}
@PostMapping("/boardmodify")
public String boardmodify2(LBMboardDTO lbmb) {
lbmservice.boardmodify(lbmb);
return "redirect:/lbm/boardlist";
}
@PostMapping("/boarddelete")
public String boarddelete(LBMboardDTO lbmb){
Logger.info("실행됨"+lbmb);
lbmservice.boarddelete(lbmb);
return "redirect:/lbm/boardlist";
}
}
membercontroller
package org.lhr.controller;
import java.util.ArrayList;
import org.lhr.DTO.MemberDTO;
import org.lhr.DTO.TodoDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/member")
public class MemberController {
private static final Logger Logger = LoggerFactory.getLogger(MemberController.class);
//Logger는 문제가 있으면 console에 남겨달라 / sysout과 같은 역할
@RequestMapping(value="/write",method=RequestMethod.GET)
public void memberWrite() {
}
//write.jsp에서 사용자가 입력한 데이터를 수집하기위한 controller (건 by 건)
@RequestMapping(value="/write",method=RequestMethod.POST)
//public void PostWrite(@RequestParam("name") String name,
// @RequestParam("age") int age) {
public void Postwrite(MemberDTO mdto) {
}
@RequestMapping(value="/ex02List",method = RequestMethod.GET)
public String ex02List(@RequestParam("ids")ArrayList<String> ids) {
Logger.info("ids"+ids);
return "ArrayList";
}/*
@InitBinder //이걸로 형변환을 해서 날짜를 가져올 수 있게끔 해줌
public void intiBinder(WebDataBinder binder){
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd"); //MM은 무조건 대문자여야함
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,false));
}*/
@RequestMapping(value="/ex03",method=RequestMethod.GET)
public String ex03(TodoDTO todo) {
Logger.info("todo : "+todo);
return "ex03";
}
@RequestMapping(value="/update",method=RequestMethod.GET)
public void memberUpdate() {
Logger.info("update");
}
@RequestMapping(value="/delete",method=RequestMethod.GET)
public void memberDelete() {
Logger.info("delete");
}
@RequestMapping(value="/read",method=RequestMethod.GET)
public void memberRead() {
Logger.info("read");
}
}
samplecontroller
package org.lhr.controller;
import org.lhr.DTO.MemberDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.lhr.DTO.MemberDTO;
@Controller
@RequestMapping("/sample") //제외하면 url주소에서 /sample을 제외하면 됨
// ex)localhost:8080/member/delete -- 삭제 localhost:8080/member/update -- 수정 에서 공통적으로 들어가는 /member/부분이 여기에해당됨
public class SampleController {
//클래스명
private static final Logger Logger = LoggerFactory.getLogger(SampleController.class);
//springframework 버전 4.3 이전 버전에서만 사용
@RequestMapping(value="/samplebasic1",method=RequestMethod.GET)
//url주소를 통해서 가면 무조건 get
public void basicGet1() {
Logger.info("samplebasic1");
//url 주소 : http://localhost8090/sample/samplebasic1
}
//springframework 버전 4.3 이후 버전에서는 둘다 가능
@GetMapping("/samplebasic3")
public String basicGet2() {
Logger.info("samplebasic3");
//url 주소 : http://localhost8090/sample/samplebasic2
return "sb3";
}
//두가지 상황 url주소랑 .jsp랑 이름을 같게 가겠다 => return 필요없음
//url 주소랑 .jsp이름을 다르게 하겠다 => return 값을 따로 설정
//JSON 타입(jackson-databind 라는 라이브러리 추가 (pom.xml에 추가하는거))
@RequestMapping(value="/json",method=RequestMethod.GET)
public @ResponseBody MemberDTO jsonGet() {
MemberDTO mdto = new MemberDTO();
// mdto.setAge(10);
// mdto.setName("정자바");
return mdto;
}
//통신방식 비동기식 통신
//동기식방식vs비동기식 방식의 차이
//동기식은 차례대로 하는것 비동기식은 끝나지않아도 다른작업도 할 수 있음
//비동기식 : 통신이 정상적으로 이루어졌을때 이루어짐
// 개발자 도구에 header status code가 정상이어야함
//ResponseEntity 타입
@RequestMapping(value="/entity",method=RequestMethod.GET)
public ResponseEntity<String> entityGet(){
String msg="{\"name\" :\"정자바\" }";
HttpHeaders header = new HttpHeaders();
header.add("Content-type","application/json;charset=UTF-8");
return new ResponseEntity<>(msg,header,HttpStatus.OK);
}
}
samplerestcontroller
package org.lhr.controller;
import org.lhr.DTO.SampleDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/sample")
public class SampleRestController {
//Rest방식에서 단순 문자열 반환
@GetMapping(value="/getText",produces="text/plain; charset=utf-8")
public String getText() {
return "안녕하세요";
}
//Rest 방식에서 객체(필통) 반환
@GetMapping(value="/getObject",produces= {MediaType.APPLICATION_JSON_UTF8_VALUE,
MediaType.APPLICATION_XML_VALUE})
public SampleDTO getObject() {
SampleDTO sd = new SampleDTO();
sd.setNo(1);
sd.setFirstName("홍");
sd.setLastName("길동");
return sd;
}
//ResponseEntity 타입 변환
@GetMapping(value="/check",params= {"height","weight"})
public ResponseEntity<SampleDTO> check(double height,double weight){
SampleDTO sd= new SampleDTO();
sd.setNo(2);
sd.setFirstName(""+height);
sd.setLastName(""+weight);
ResponseEntity<SampleDTO> result=null;
if(height <150) {
result=ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(sd);
}else {
result=ResponseEntity.status(HttpStatus.OK).body(sd);
}return result;
}
}
'Programming > 게시판 만들기' 카테고리의 다른 글
[게시판 만들기] MAPPER (0) | 2021.02.14 |
---|---|
[게시판 만들기] DTO (0) | 2021.02.14 |
[게시판 만들기] member add / list / detail (0) | 2021.02.14 |
[게시판 만들기] addmember / login / boardwrite / boardmodify / boardlist / boarddetail (0) | 2021.02.14 |
[게시판 만들기] detail / write / update / list (0) | 2021.02.14 |