반응형

*개발 준비 진행


초반부터 책을 보고 잘 따라했다면 문제 없는 과정이다


-환경 설정


1
2
3
4
5
6
7
<bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
        <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/book_ex?
         useSSL=false&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"></property>
        <property name="username" value="root"></property>
        <property name="password" value="1234"></property>                  
</bean>
cs



디비 주소 뒤에 useSSL 여부에 따라 에러가 나는 경우가 있으니 주의하도록 하자



-테스트 작성


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.common.web;
 
import java.sql.Connection;
 
import javax.inject.Inject;
import javax.sql.DataSource;
 
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/root-context.xml"})
public class DataSourceTest {
    
    @Inject
    private DataSource ds;
    
    @Test
    public void testConnection() throws Exception{
        
        try(Connection con = ds.getConnection()){
            
            System.out.println(con +"git bash commit용 테스트 메세지 ");
            
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }
 
}
cs


중간에 git 테스트 때문에 수정내역을 보기위해 했던 수정이다 넘어가자



- 빌드 테스트












로그와 Junit 도 Success


-테이블 생성



1
2
3
4
5
6
7
8
9
10
create table tbl_board(
    bno INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(200NOT NULL,
    content TEXT NULL,
    writer VARCHAR(50NOT NULL,
    regdate TIMESTAMP NOT NULL DEFAULT now(),
    viewcnt INT DEFAULT 0,
    PRIMARY KEY (bno)
    
);
cs




-용도별 쿼리 분류


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
게시물 등록
 
INSERT INTO `book_ex`.`tbl_board`
(
`title`,
`content`,
`writer`)
VALUES
(
'제목입니다',
'내용입니다',
'user00');
 
조회
 
select * from tbl_board where bno = 1;
 
전체 목록
 
select * from tbl_board where bno > 0 order by bno desc;
 
수정
 
update tbl_board set title = '수정된 제목' where bno = 1;
 
삭제
 
delete from tbl_board where bno = 1;
cs





-web.xml 에 필터 추가



1
2
3
4
5
6
7
8
9
10
11
12
13
    <filter>        
        <filter-name>enconding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
cs


애플리케이션을 제작하다보면 한글 처리가 문제 될때가 많기때문에 미리 등록한다

톰캣에 설정하는 부분도있고 디비주소에 설정하는 부분도 있고 한글 처리는 항상 문제가 되는듯하다



-bootstrap, html 


해당 저서에는 bootstrap과 관련 템플릿을 통해서 웹페이지를 구성하기때문에

해당 자료를 다운받아 프로젝트에 넣어야한다


https://cafe.naver.com/gugucoding/798


여기서 받을수있다


static.zip 파일과 include.zip 파일을 압축 풀어서


bootstrap,dist,plugin 파일은 webapp/resource 아래에 두고

include 파일은 webapp/WEB-INF/views 아래에 두면된다




-html 파일 수정


home.jsp 파일을 수정해야한다


그전 장에서 톰캣의 설정이 되어있어야 테스트가 가능하다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="include/header.jsp" %>
 
<!-- Main content -->
<section class="content">
    <div class="row">
        <!-- left colum -->
        <div class="col-md-12">
            <!-- genaral from element -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"> HOME PAGE</h3>
                </div>
            </div>
        </div><!-- /.col (left) -->
    </div><!-- /.row -->
</section><!-- /.content -->
 
<%@ include file="include/footer.jsp" %>
cs




전부 적용되었는지 확인하고 서버를 실행해보면 디자인이 적용된걸 확인할수있다


반응형

+ Recent posts