SW과정 Spring 11일차 - 0809
Controller
package com.ksa.fullstack.controller;
import java.sql.Timestamp;
import java.util.ArrayList;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ksa.fullstack.dto.BBSDto;
import com.ksa.fullstack.service.FullStackService;
/**
* Handles requests for the application home page.
*/
@Controller
public class FullStackController {
private static final Logger logger = LoggerFactory.getLogger(FullStackController.class);
private BBSDto article;
private ArrayList<BBSDto> articleList;
@Autowired //스프링이 지원하는 애노테이션이고 타입으로 찾음
FullStackService fullStackService;
@RequestMapping(value = "/list.ksa", method = RequestMethod.GET)
public String list(Model model) {
logger.info("컨트롤러 메소드 동작");
fullStackService.list();
articleList = new ArrayList<BBSDto>();
for(int i =1; i<=5;i++) {
article= new BBSDto();
article.setArticleNum(i);
article.setId("fasfsaf");
article.setTitle("sdfdsafsadfsdaf");
article.setContent("fsafafsadfsadf");
article.setWriteDate(new Timestamp(10000000));
articleList.add(article);
}
model.addAttribute("list","금요일입니다" );
model.addAttribute("articleList",articleList );
return "list";
}
}
Dao-impl
package com.ksa.fullstack.dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
@Repository
public class FullStackDaoImpl implements FullStackDao {
private static final Logger logger = LoggerFactory.getLogger(FullStackDaoImpl.class);
@Override
public void list() {
logger.info("dao 메소드 동작");
}
}
BBS-Dto
package com.ksa.fullstack.dto;
import java.sql.Timestamp;
public class BBSDto {
private int articleNum;
private String id;
private String title;
private String content;
private Timestamp writeDate;
public int getArticleNum() {
return articleNum;
}
public void setArticleNum(int articleNum) {
this.articleNum = articleNum;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Timestamp getWriteDate() {
return writeDate;
}
public void setWriteDate(Timestamp writeDate) {
this.writeDate = writeDate;
}
@Override
public String toString() {
return "BBSDto [articleNum=" + articleNum + ", id=" + id + ", title=" + title + ", content=" + content
+ ", writeDate=" + writeDate + "]";
}
}
Service
package com.ksa.fullstack.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ksa.fullstack.dao.FullStackDao;
@Service
public class FullStackServiceImpl implements FullStackService {
private static final Logger logger = LoggerFactory.getLogger(FullStackServiceImpl.class);
@Autowired
FullStackDao fullStackDao;
@Override
public void list() {
logger.info("서비스클래스 메소드 동작");
fullStackDao.list();
}
}