-
Notifications
You must be signed in to change notification settings - Fork 25
6주차 미션 / 서버 1조 이준용 #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
98b9d70
18c1f18
558ce02
afbac4e
18d56fb
978790f
024948b
ed766c8
aa19e29
9330d5f
699f385
dc2fd96
42fac50
45795f8
406a4dd
d4e1a8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,34 @@ | ||
| package core.jdbc; | ||
|
|
||
| import org.apache.commons.dbcp2.BasicDataSource; | ||
|
|
||
| import javax.sql.DataSource; | ||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| public class ConnectionManager { | ||
| private static final String DB_DRIVER = "org.h2.Driver"; | ||
| private static final String DB_URL = "jdbc:h2:~/jwp-basic"; | ||
| private static final String DB_USERNAME = "sa"; | ||
| private static final String DB_PW = ""; | ||
|
|
||
| private static BasicDataSource ds; | ||
| public static DataSource getDataSource() { | ||
| if (ds == null) { | ||
| ds = new BasicDataSource(); | ||
| ds.setDriverClassName(DB_DRIVER); | ||
| ds.setUrl(DB_URL); | ||
| ds.setUsername(DB_USERNAME); | ||
| ds.setPassword(DB_PW); | ||
| } | ||
| return ds; | ||
| } | ||
|
|
||
| public static Connection getConnection() { | ||
| try { | ||
| return getDataSource().getConnection(); | ||
| } catch (SQLException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
| } | ||
| //package core.jdbc; | ||
| // | ||
| //import org.apache.commons.dbcp2.BasicDataSource; | ||
| // | ||
| //import javax.sql.DataSource; | ||
| //import java.sql.Connection; | ||
| //import java.sql.SQLException; | ||
| // | ||
| //public class ConnectionManager { | ||
| // private static final String DB_DRIVER = "org.h2.Driver"; | ||
| // private static final String DB_URL = "jdbc:h2:~/jwp-basic"; | ||
| // private static final String DB_USERNAME = "sa"; | ||
| // private static final String DB_PW = ""; | ||
| // | ||
| // private static BasicDataSource ds; | ||
| // public static DataSource getDataSource() { | ||
| // if (ds == null) { | ||
| // ds = new BasicDataSource(); | ||
| // ds.setDriverClassName(DB_DRIVER); | ||
| // ds.setUrl(DB_URL); | ||
| // ds.setUsername(DB_USERNAME); | ||
| // ds.setPassword(DB_PW); | ||
| // } | ||
| // return ds; | ||
| // } | ||
| // | ||
| // public static Connection getConnection() { // DB의 커넥션 풀 중 커넥션 하나를 받아올 수 있음 | ||
| // try { | ||
| // return getDataSource().getConnection(); | ||
| // } catch (SQLException e) { | ||
| // throw new IllegalStateException(e); | ||
| // } | ||
| // } | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| //package core.jdbc; | ||
| // | ||
| // | ||
| //import java.sql.Connection; | ||
| //import java.sql.PreparedStatement; | ||
| //import java.sql.ResultSet; | ||
| //import java.sql.SQLException; | ||
| //import java.sql.Statement; | ||
| //import java.util.ArrayList; | ||
| //import java.util.List; | ||
| // | ||
| //public class JdbcTemplate<T> { | ||
| // | ||
| // public void update(String sql, PreparedStatementSetter pstmtSetter) throws SQLException { | ||
| // try (Connection conn = ConnectionManager.getConnection(); | ||
| // PreparedStatement pstmt = conn.prepareStatement(sql);) { | ||
| // | ||
| // pstmtSetter.setParameters(pstmt); | ||
| // pstmt.executeUpdate(); | ||
| // } | ||
| // } | ||
| // | ||
| // public void update(String sql, PreparedStatementSetter pstmtSetter, KeyHolder holder) throws SQLException { | ||
| // try (Connection conn = ConnectionManager.getConnection(); | ||
| // PreparedStatement pstmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { | ||
| // | ||
| // pstmtSetter.setParameters(pstmt); | ||
| // pstmt.executeUpdate(); | ||
| // | ||
| // if (holder != null) { | ||
| // try (ResultSet rs = pstmt.getGeneratedKeys()) { | ||
| // if (rs.next()) { | ||
| // holder.setId(rs.getLong(1)); | ||
| // } | ||
| // } | ||
| // } | ||
| // } | ||
| // } | ||
| // | ||
| // | ||
| // public List<T> query(String sql, RowMapper<T> rowMapper) throws SQLException { | ||
| // List<T> objects = new ArrayList<>(); | ||
| // | ||
| // try (Connection conn = ConnectionManager.getConnection(); | ||
| // PreparedStatement pstmt = conn.prepareStatement(sql); | ||
| // ResultSet rs = pstmt.executeQuery();) { | ||
| // | ||
| // while (rs.next()) { | ||
| // T object = rowMapper.mapRow(rs); | ||
| // objects.add(object); | ||
| // } | ||
| // } | ||
| // return objects; | ||
| // } | ||
| // | ||
| // public T queryForObject(String sql, PreparedStatementSetter pstmtSetter, RowMapper<T> rowMapper) throws SQLException { | ||
| // T object = null; | ||
| // | ||
| // try(Connection conn = ConnectionManager.getConnection(); | ||
| // PreparedStatement pstmt = conn.prepareStatement(sql);) { | ||
| // pstmtSetter.setParameters(pstmt); | ||
| // | ||
| // try (ResultSet rs = pstmt.executeQuery()) { | ||
| // if (rs.next()) { | ||
| // object = rowMapper.mapRow(rs); | ||
| // } | ||
| // } | ||
| // } | ||
| // | ||
| // return object; | ||
| // } | ||
| // | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //package core.jdbc; | ||
| // | ||
| //public class KeyHolder { | ||
| // private long id; | ||
| // | ||
| // public void setId(long id) { | ||
| // this.id = id; | ||
| // } | ||
| // | ||
| // public long getId() { | ||
| // return id; | ||
| // } | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //package core.jdbc; | ||
| // | ||
| //import java.sql.PreparedStatement; | ||
| //import java.sql.SQLException; | ||
| // | ||
| //@FunctionalInterface | ||
| //public interface PreparedStatementSetter { | ||
| // void setParameters(PreparedStatement ps) throws SQLException; | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //package core.jdbc; | ||
| // | ||
| //import jwp.model.User; | ||
| // | ||
| //import java.sql.ResultSet; | ||
| //import java.sql.SQLException; | ||
| // | ||
| //@FunctionalInterface | ||
| //public interface RowMapper<T> { | ||
| // T mapRow(ResultSet rs) throws SQLException; | ||
| // | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package jwp; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class WebServerLauncher { | ||
| public static void main(String[] args) throws Exception { | ||
| SpringApplication.run(WebServerLauncher.class, args); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //package jwp.controller; | ||
| // | ||
| //import javax.servlet.ServletException; | ||
| //import javax.servlet.http.HttpServletRequest; | ||
| //import javax.servlet.http.HttpServletResponse; | ||
| //import java.io.IOException; | ||
| //import java.sql.SQLException; | ||
| // | ||
| //public interface Controller { | ||
| // String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException; | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //package jwp.controller; | ||
| // | ||
| // | ||
| //import jwp.model.Question; | ||
| //import jwp.model.User; | ||
| //import jwp.service.QuestionService; | ||
| //import jwp.support.session.UserSessionUtils; | ||
| //import lombok.RequiredArgsConstructor; | ||
| //import org.springframework.stereotype.Controller; | ||
| //import org.springframework.web.bind.annotation.PostMapping; | ||
| //import org.springframework.web.bind.annotation.RequestMapping; | ||
| //import org.springframework.web.bind.annotation.RequestParam; | ||
| // | ||
| //import javax.servlet.ServletException; | ||
| //import javax.servlet.http.HttpServletRequest; | ||
| //import javax.servlet.http.HttpServletResponse; | ||
| //import javax.servlet.http.HttpSession; | ||
| //import java.io.IOException; | ||
| //import java.sql.SQLException; | ||
| // | ||
| //@Controller | ||
| //@RequestMapping("/qna") | ||
| //@RequiredArgsConstructor | ||
| //public class CreateQuestionController{ | ||
| // private final QuestionService questionService; | ||
| // @PostMapping("/create") | ||
| // public String createQuestion(@RequestParam String title, | ||
| // @RequestParam String contents, | ||
| // HttpSession session) { | ||
| // User user = UserSessionUtils.getUserFromSession(session); | ||
| // if (user == null) { | ||
| // return "redirect:/user/loginForm"; | ||
| // } | ||
| // questionService.createQuestion(user.getUserId(), title, contents); | ||
| // return "redirect:/"; | ||
| // } | ||
| //} | ||
|
Comment on lines
+1
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 주석 처리된 파일을 삭제하세요. 전체 파일이 주석 처리되어 있어 실행되지 않는 데드 코드입니다. 이전 리뷰에서 지적된 중복 매핑 문제를 주석 처리로 회피했지만, 이는 근본적인 해결책이 아닙니다. 버전 관리 시스템에 코드 이력이 남아있으므로 필요시 복원할 수 있습니다. 코드베이스를 깔끔하게 유지하기 위해 이 파일을 완전히 삭제해주세요. 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //package jwp.controller; | ||
| // | ||
| //import jwp.support.session.UserSessionUtils; | ||
| //import org.springframework.stereotype.Controller; | ||
| //import org.springframework.web.bind.annotation.GetMapping; | ||
| //import org.springframework.web.bind.annotation.RequestMapping; | ||
| // | ||
| //import javax.servlet.http.HttpSession; | ||
| // | ||
| //@Controller | ||
| //@RequestMapping("/qna") | ||
| //public class CreateQuestionFormController { | ||
| // | ||
| // @GetMapping("/form") | ||
| // public String showForm(HttpSession session) { | ||
| // if (UserSessionUtils.isLogined(session)) { | ||
| // return "qna/form.jsp"; | ||
| // } | ||
| // return "redirect:/user/loginForm"; | ||
| // } | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //package jwp.controller; | ||
| // | ||
| //import jwp.model.User; | ||
| //import jwp.service.UserService; | ||
| //import lombok.RequiredArgsConstructor; | ||
| //import org.springframework.stereotype.Controller; | ||
| //import org.springframework.web.bind.annotation.ModelAttribute; | ||
| //import org.springframework.web.bind.annotation.PostMapping; | ||
| //import org.springframework.web.bind.annotation.RequestMapping; | ||
| // | ||
| //@Controller | ||
| //@RequestMapping("/user") | ||
| //@RequiredArgsConstructor | ||
| //public class CreateUserController { | ||
| // private final UserService userService; | ||
| // | ||
| // @PostMapping("/signup") | ||
| // public String createUser(@ModelAttribute User user) { | ||
| // userService.createUser(user); | ||
| // return "redirect:/user/list"; | ||
| // } | ||
| //} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySQL 커넥터 의존성 버전을 명시하세요.
MySQL 커넥터에 버전이 명시되어 있지 않습니다. Spring Boot의 의존성 관리가 처리할 수 있지만,
mysql-connector-java는 deprecated되었으며mysql-connector-j로 대체되었습니다.다음과 같이 수정하는 것을 권장합니다:
📝 Committable suggestion
🤖 Prompt for AI Agents