iknowahra / cspiEdu

CSPI OJT
0 stars 0 forks source link

2021.10.14 교육내용 정리_HS #24

Open choi-hyeongseok opened 2 years ago

choi-hyeongseok commented 2 years ago

client - controller - service - dao

과정

client(viewer2.jsp) -> FormController.java -> FormTestService.java (FormTestServiceImpl.java) -> FormTestDao.java -> sql.xml -> database


FormController.java

package com.cspi.test;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.LinkedTransferQueue;

import javax.servlet.http.HttpServletRequest;

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 org.springframework.web.bind.annotation.RequestParam;

import com.cspi.test.service.FormTestService;
import com.cspi.test.vo.FormTestVo;

@Controller
@RequestMapping(value= "form")
public class FormController {

    /**
     * 
     * form
     * @return
     */

    // service 사용자 별로 메뉴얼을 가져와야 되기 때문에
    // 의존성 주입
    @Autowired
    FormTestService service;

    @RequestMapping(value = "viewer2", method = RequestMethod.GET)
    public String viewer(Model model) {  

        // 굳이 생성을 하지 않아서 가져와서 생성이 된다.
        List<FormTestVo> list = null; 

        try {
            list = service.selectFormTest(1);
            System.out.println(list.toString());
        } catch (Exception e) {
            // TODO: handle exception
        e.printStackTrace();
        System.out.println("select 를 데이터를 가져오지 못하였다.");
        }

        model.addAttribute("list",list);

        return "form/viewer2";
    }
}
List<FormTestVo> list  = service.selectFormTest(1);

try catch

try {
        } catch (Exception e) {
            // TODO: handle exception
        e.printStackTrace();
        System.out.println("error : "+e.messages());
        }

viewer2.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ 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>
<c:forEach items="${list}" var="item" >
    <p> ${item.title}</p>
    <p> ${item.content}</p>
    <br>
</c:forEach>

</body>
</html>

FormTestService.java

package com.cspi.test.service;

import java.util.List;

import com.cspi.test.vo.FormTestVo;

public interface FormTestService {
    // 
    public List<FormTestVo> selectFormTest(int no);

}

FormTestServiceImpl.java

package com.cspi.test.service;

import java.util.List;

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

import com.cspi.test.dao.FormTestDao;
import com.cspi.test.vo.FormTestVo;

// 필요한 것만 가져와서 필요할 때만 실행 되게 된다.

@Service("FormTestService")
public class FormTestServiceImpl implements FormTestService {

    @Autowired
    FormTestDao dao;
    // 재사용

    @Override
    public List<FormTestVo> selectFormTest(int no) {
        // TODO Auto-generated method stub
        return dao.selectFormTest(no);
    }

}

FormTestDao.java

package com.cspi.test.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.cspi.test.vo.FormTestVo;

@Repository("FormTestDao")
public class FormTestDao {

    /*
     * board 테이블
     * board 테이블에서 1번 글을 가져오는 쿼리랑 연결하기
     */

    // 의존성 주입
    // 이 객체를 bean에 주입
    @Autowired
    SqlSession sqlSession; // mybatis 와 스프링이 db와 통신하기 위해서 만들어주는 세션

    public List<FormTestVo> selectFormTest(int no){

        // selectForm 쿼리 문을 불러온다.
        return sqlSession.selectList("formTest.selectFormTest",no); 
    }

}

새롭게 알게된 정보

intercepter

참고 링크: https://tinyurl.com/2vrx25yk

heroku

참고 링크: https://tinyurl.com/2hmc73bw

url 줄이기

참고 링크: https://tinyurl.com/app

이미지 스토리지 S3

참고 링크: https://tinyurl.com/253ckha6

light sell aws

참고 링크: https://aws.amazon.com/ko/lightsail/