1. BoardController

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class BoardController {
 
    @Autowired
    BoardService boardService;
    
    @Autowired
    CommentService commentService;
    
    @RequestMapping("boardList")
    public String toBoardList(Model model, Board board,
            @RequestParam(required = false, defaultValue= "1")int page,
            @RequestParam(required = false, defaultValue= "1")int range) throws Exception {
        //전체 게시글 개수
        int listCnt = boardService.getBoardListCnt();
        
        //Pagination 
        Pagination pagination = new Pagination();
        pagination.pageInfo(page, range, listCnt);
        
        model.addAttribute("pagination", pagination);
        model.addAttribute("board", boardService.selectAll(pagination));
        return "board/boardList";
    }
    
    @RequestMapping("boardWrite")
    public String toBoardWrite() {
        return "board/boardWrite";
    }
    
    @RequestMapping("boardInsert")
    public String boardInsert(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("boardView")
    public String toBoardView(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        model.addAttribute("comment", commentService.selectAll(board.getBoardId()));
        return "board/boardView";
    }
    
    @RequestMapping("toBoardEdit")
    public String toBoardEdit(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        return "board/boardEdit";
    }
    
    @RequestMapping("boardEdit")
    public String boardEdit(Board board) {
        return "redirect:boardView?boardId=" + board.getBoardId();
    }
    
    @RequestMapping("boardDelete")
    public String boardDelete(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("toBoardReply")
    public String toBoardReply(Board board, Model model) {
        model.addAttribute("board", board);
        return "board/boardReply";
    }
    
    @RequestMapping("boardReply")
    public String BoardReply(Board board, HttpServletRequest request) {
        return "redirect:boardList";
    }
    
    @RequestMapping("search")
    public String search(@RequestParam("search"String search, @RequestParam("type"String type, Model model) {
        model.addAttribute("result"boardService.search(search, type));
        System.out.println(boardService.search(search, type));
        return "board/search";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentController

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
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class CommentController {
 
    @Autowired
    CommentService commentService;
    
    @RequestMapping("postComment")
    public String postComment(Comment comment) {
        return "redirect:boardView?boardId=" + comment.getBoardId();
    }
    
    @RequestMapping("deleteComment")
    public String deleteComment(Comment comment) {
        return "redirect:boardView?boardId="+ comment.getBoardId();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberController

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
 
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
 
 
@Controller
public class MemberController {
 
    @Autowired 
    MemberService memberService;
 
    @RequestMapping("toLogin")
    public String toLogin() {
        
        return "member/login";
    }
    
    @RequestMapping("loginCheck")
    public String login(Boardmember member, HttpSession session, Model model) {
        if(memberService.checkMember(member)) {
            model.addAttribute("success""Login Success!");
            session.setAttribute("session", member);
            return "home";
        } else {
            model.addAttribute("fail""Try reentering username or password");
            return "member/login";
        }
    }
    
    @RequestMapping("toRegister")
    public String toRegister() {
        return "member/register";
    }
    
    @RequestMapping("register")
    public String register(Boardmember member, Model model, BindingResult bindingResult) {
        memberService.registerMember(member);
        if(bindingResult.hasErrors()) {
            return "member/register";
        } else {
            model.addAttribute("success""Register Success! Now login");
        }
        
        
        return "home";
    }
    
    @RequestMapping("logout")
    public String logout(HttpSession session, Model model) {
        session.invalidate();
        model.addAttribute("success""Logout Success!");
        return "home";
    }
    
    
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Various html  (0) 2019.11.14
Settings  (0) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14

1. a. Board interface

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
 
public interface BoardService {
 
    List<Board> selectAll(Pagination pagination);
    void insert(Board board);
    Board select(Board board);
    void delete(Board board);
    void update(Board board);
    void hit(int board);
    void reply(Board board);
    List<Board> search(String search, String type);
    
    public int getBoardListCnt() throws Exception;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. BoardServiceImpl

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
 
import org.springframework.stereotype.Service;
 
 
@Service
public class BoardServiceImpl implements BoardService{
 
    @Autowired
    BoardMapper boardMapper;
 
    @Override
    public List<Board> selectAll(Pagination pagination) {
        
        return boardMapper.selectAll(pagination);
    }
 
    @Override
    public void insert(Board board) {
    }
 
    @Override
    public Board select(Board board) {
        return boardMapper.select(board);
    }
 
    @Override
    public void delete(Board board) {
    }
 
    @Override
    public void update(Board board) {
    }
 
    @Override
    public void hit(int board) {
        boardMapper.hit(board);
    }
 
    @Override
    public void reply(Board board) {
        boardMapper.replyShape(board);
    }
 
    @Override
    public List<Board> search(String search, String type) {
        System.out.println(search + type);
        System.out.println("its boardserviceimpl" + boardMapper.search(search, type));
        return boardMapper.search(search, type);
    }
    
    @Override
    public int getBoardListCnt() throws Exception {
        return boardMapper.getBoardListCnt();
    }
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2.a. CommentServic interface

1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
public interface CommentService {
    List<Comment> selectAll(int boardId);
    void insert(Comment comment);
    void delete(int comment);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. commentserviceimpl 

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
34
35
 
 
import org.springframework.stereotype.Service;
 
 
@Service
public class CommentServiceImpl implements CommentService{
 
    @Autowired
    CommentMapper commentMapper;
 
    @Override
    public List<Comment> selectAll(int comment) {
        return commentMapper.selectAll(comment);
    }
 
    @Override
    public void insert(Comment comment) {
    }
 
    @Override
    public void delete(int comment) {
    }
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. a. MemberService interface

1
2
3
4
5
6
7
8
9
 
 
public interface MemberService {
    boolean checkMember(Boardmember member);
    void registerMember(Boardmember member);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. MemberServiceImpl 

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
 
import org.springframework.stereotype.Service;
 
 
@Service
public class MemberServiceImpl implements MemberService{
 
    @Autowired
    MemberMapper memberMapper;
    
    @Override
    public boolean checkMember(Boardmember member) {
        return memberMapper.checkMember(member) != null;
    }
 
    @Override
    public void registerMember(Boardmember member) {
        memberMapper.registerMember(member);
    }
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Settings  (0) 2019.11.14
Controller  (1) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
import lombok.Data;
 
@Data
public class Pagination {
    
    private int listSize = 10//한 페이지당 보여질 리스트 개수
    private int rangeSize = 10//한 페이지 범위에 보여질 페이지의 개수
    private int page; //현재 목록의 페이지 번호
    private int range; //각 페이지 범위 시작 번호
    private int listCnt; //전채 게시물의 개수
    private int pageCnt; //전체 페이지 범위의 개수
    private int startPage; //각 페이지 범위 시작 번호
    private int startList; //해당 페이지 당 게시판 시작 번호
    private int endPage; //각 페이지 범위 끝 번호
    private boolean prev; //이전 페이지 버튼 여부
    private boolean next; //다음 페이지 버튼 여부
    
    public void pageInfo(int page, int range, int listCnt) {
        this.page = page;
        this.range = range;
        this.listCnt = listCnt;
        
        //전체 페이지수
        this.pageCnt = (intMath.ceil(listCnt/listSize);
        
        //시작 페이지
        this.startPage = (range - 1* rangeSize + 1;
        
        //끝 페이지
        this.endPage = range * rangeSize;
        
        //게시판 시작번호
        this.startList = (page - 1* listSize;
        
        //이전 버튼 상태
        this.prev = range == 1 ? false : true;
        
        //다음 버튼 상태
        this.next = endPage > pageCnt ? false : true;
        if(this.endPage > this.pageCnt) {
            this.endPage = this.pageCnt + 1;
            this.next = false;
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
Caleb Curry's Database design course  (0) 2019.11.08

1. BoardMapper 

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
 
 
 
 
public interface BoardMapper {
 
    List<Board> selectAll(Pagination pagination);
    void insert(Board board);
    Board select(Board board);
    void delete(Board board);
    void update(Board board);
    void hit(int board);
    void reply(Board board);
    void replyShape(Board board);
//    List<Board> search(@Param("search") String search,@Param("type") String type);
    List<Board> search(@Param("search"String search,@Param("type"String type);
    
    int getBoardListCnt();
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentMapper

1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
public interface CommentMapper {
    void insert(Comment comment);
    List<Comment> selectAll(int comment);
    void delete(int comment);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberMapper

1
2
3
4
5
6
7
8
9
10
 
 
public interface MemberMapper {
    
    Boardmember checkMember(Boardmember member);
    void registerMember(Boardmember member);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

1. BoardMapper xml

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
 
    <select id="selectAll" resultType="board">
        select * from board 
        order by bGroup desc, bStep asc
        limit #{startList}, #{listSize}
    </select>
    
    <select id="getBoardListCnt" resultType="int">
        select count(*) listCnt 
        from board
    </select>
 
    <insert id="insert" parameterType="board">
        insert into board (bUsername, bTitle, bContent, bDate, bHit, bGroup, bIndent, bStep)
        values (#{bUsername}, #{bTitle}, #{bContent}, now(), 0, 
            (select max(boardId)+1 from board bo), 0, 0)
    </insert>
    
    <select id="select" parameterType="board" resultType="Board">
        select * from board 
        where boardId = #{boardId}
    </select>
    <update id="update" parameterType="board">
        update board
        set bTitle = #{bTitle}, bContent = #{bContent}
        where boardId = #{boardId}
    </update>
    <delete id="delete" parameterType="board">
        delete from board
        where boardId = #{boardId}
    </delete>
    
    <update id="hit" parameterType="int">
        update board
        set bHit = bHit +1
        where boardId = #{boardId}
    </update>
    
    <insert id="reply" parameterType="board">
        insert into board(bUsername, bTitle, bContent, bDate, bHit, bGroup, bIndent, bStep)
        values(#{bUsername}, #{bTitle}, #{bContent}, now(), 0, #{bGroup}, #{bIndent} + 1, #{bStep} +1)
    </insert>
    
    <update id="replyShape" parameterType="board">
        update board 
        set bStep = #{bStep} + 1
        where bGroup = #{bGroup} and bStep > #{bStep}
    </update>
    
    <select id="search" parameterType="map" resultType="board">
<!--     <bind name="result" value="'%' + #{search} + '%'"/> -->
        select * from board
        <trim prefix="where" prefixOverrides="and|or">
            <if test="type==btitle">
                and btitle like concat('%',#{search},'%')
            </if>
            <if test="type==bcontent">
                and bcontent like concat('%',#{search},'%')
            </if>
        </trim>
<!--         where #{type} like concat('%',#{search},'%') -->
<!--         select("*"); -->
<!--         from("board"); -->
<!--         where("#{type} like '%' #{search} '%'"); -->
        
    </select>
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentMapper xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
    
    <select id="selectAll" parameterType="int" resultType="comment">
        select * from comment 
        where boardId = #{boardId}
        order by commentId desc
    </select>
    
    <insert id="insert" parameterType="comment">
        insert into comment(boardId, username, content, cDate, cGroup, cIndent, cStep, cLike)
        values(#{boardId}, #{username}, #{content}, now(), (select max(commentId) from comment co) +1, 0, 0, 0)
    </insert>
    
    <delete id="delete" parameterType="int">
        delete from comment 
        where commentId = #{commentId}
    </delete>
    
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberMapper xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
    
    
    <select id="checkMember" parameterType="Boardmember" resultType="Boardmember">
        select * from Boardmember
        where username = #{username} and password = #{password}
    </select>
    
    <insert id="registerMember" parameterType="Boardmember">
        insert into boardmember (username, password, email, gender, birthday, joinDate)
        values (#{username}, #{password}, #{email}, #{gender}, #{birthday}, now())
    </insert>
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
Caleb Curry's Database design course  (0) 2019.11.08

DTO/bean/vo

1. 게시판 board

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
 
 
import lombok.Data;
 
@Data
public class Board extends Pagination{
    
    private int boardId;
    public String bUsername;
    private String bTitle;
    private String bContent;
    private Timestamp bDate;
    private int bHit;
    private int bGroup;
    private int bIndent;
    private int bStep;
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
 

2. 회원 Boardmember

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
 
import lombok.Data;
 
@Data
public class Boardmember {
    private int memberId;
    private String username;
    private String password;
    private String email;
    private String gender;
    private Timestamp joinDate;
    private Timestamp birthday;
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. 댓글 Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
import lombok.Data;
 
@Data
public class Comment {
 
    private int commentId;
    private int boardId;
    private String username;
    private String content;
    private Timestamp cDate;
    private int cGroup;
    private int cIndent;
    private int cStep;
    private int cLike;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
Caleb Curry's Database design course  (0) 2019.11.08

I wanted to create a mini project where i designed from start to end by myself since during my time in the bootcamp, I always worked with others on all of my projects. For past week, I started studying algorithm because I just finished up my bootcamp courses about a month ago, and took two weeks to prepare for an korea engineer exam(?) and finally had some time to study things I wanted to study which is algorithms. But I realized I first need to find a job first to improve my skills as a developer. Because having first hand experience inside the field is much much better than doing mini projects and studying from books by myself. So my goal is to first find a job that suits my needs and then start studying things I want to study again. 

And as a starting junior developer, the most important thing is basic knowledge of the field I am trying to be hired for which is web developer or backend developer. The next important thing is obviously a portfolio. As I was creating my portfolio, I realized I never did a project by myself so this eventually made me me want start a mini shopping mall project. 

I started to plan out what kind of features and how site was going to be by benchmarking other shopping mall sites and as I was planning out the database structure of the site I was going to create, I realized I did not know a lot of things that was required to create a functional and proper database. 

And the obvious place to go to is youtube. Found a course by Caleb Curry, teaching from the basics and up to joins. The course does not talk about specific sql commands but rather on how to design a functional database which is exactly what I needed. 

I had the basic knowledge of database structure design because I had done projects before. But figured I would tie up some loose ends and the course was the perfect fit. Here are thigns I learned which I thought was pretty useful :

 

1. definition of a surrogate key and natural key and there differences.

previously when designing a database, I was taught to add an id for every table I created but was not taught the reason for doing such a procedure. I was setting up a surrogate key. surrogate keys are unique identified keys like natural key but does not have real value like a natural key. natural key is a unqiue identified key that already exists in the table like a username. 

 

2. normal forms

I studied the concept of normal forms when I was preparing for the korea engineer exam but did not know specifically how to apply to a table. 1nf assigns an atomic value for each attributes. 2nf removes all partial relations. 3nf make sure non keys are dependent to other non keys

 

3. joins

inner joins, left joins, right joins, outer joins and very new to me a self join

 

I want to keep track of what I have studied like this from now on. If the course is in Korean, I will post it in korean with english comments and if and probably mostly is in english then i will post it in english 

 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14

+ Recent posts