This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleServlet extends HttpServlet { | |
//doPost 재 정의 | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.setContentType("text/html; charset=UTF-8"); | |
// Response 객체의 PrintWriter를 사용해 브라우저에 HTML을 출력한다. | |
PrintWriter out = resp.getWriter(); | |
out.println("<HTML><HEAD><TITLE>HelloServlet</TITLE></HEAD>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
@AllArgsConstructor | |
@NoArgsConstructor | |
public class Student { | |
private String id; | |
private String name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableWebMvc | |
@ComponentScan("me.spring5.spittr.web") | |
public class WebConfig implements WebMvcConfigurer { | |
@Bean | |
public ViewResolver viewResolver() { | |
InternalResourceViewResolver resolver = new InternalResourceViewResolver(); //view resolver | |
resolver.setPrefix("/WEB-INF/views/"); | |
resolver.setSuffix(".jsp"); | |
resolver.setExposeContextBeansAsAttributes(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class HomeController { | |
@RequestMapping(value = "/" ,method = RequestMethod.GET) | |
public String home() { | |
return "home"; //view name | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpittrWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | |
@Override | |
protected Class<?>[] getRootConfigClasses() { | |
return new Class[] {RootConfig.class}; | |
} | |
@Override | |
protected Class<?>[] getServletConfigClasses() { | |
return new Class[] {WebConfig.class, SwaggerConfig.class}; //설정 클래스를 명시 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class URLreplace { | |
static String replaceSpaces(String s, int len) { | |
int spaceCount = 0, index, i = 0; | |
char[] originStr = s.toCharArray(); | |
for (i = 0; i < len; i++) { | |
if (originStr[i] == ' ') { | |
spaceCount++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Permutation { | |
boolean permutation(String s, String t) { | |
if (s.length() != t.length()) { | |
return false; | |
} | |
//memo 저장 공간 | |
int[] marking = new int[128]; | |
//첫 번째 문자열을 memo +1 | |
char[] s_array = s.toCharArray(); | |
for (char c : s_array) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UniqueChars { | |
boolean isUniqueChars(String str) { | |
if (str.length() > 128) return false; | |
//미리 선언된 배열 -> 문자 요소가 등장할 때마다 메모하는 용도로 사용 | |
boolean[] char_set = new boolean[128]; | |
for (int i = 0; i < str.length(); i++) { | |
//각 문자열을 문자 요소로 변경 | |
int val = str.charAt(i); | |
if (char_set[val]) { | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************** | |
Item01 장점3> 해당 객체의 하위 타입을 리턴할 수 있다. | |
Item01 장점4> 리턴하는 객체의 클래스가 입력 매개변수에 따라 다른 리턴값을 갖게 할 수 있다. | |
*************************************************************/ | |
public class Drill { | |
private String id; | |
private int num; | |
public Drill() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************************************************************** | |
Item01 장점2> 객체를 호출 할 때마다 매번 새로운 객체를 생성할 필요는 없다. | |
***********************************************************************/ | |
public class Drill { | |
private static final Drill GOOD_ID = new Drill.withId("minikuma"); | |
private static final Drill GOOD_NUM = new Drill.withNum(100); | |
private String id; | |
private int num; |
NewerOlder