










[AJAX] Ajax Code E xamples.. [Book] About the book.. [CSS] CSS Code E xamples.. [DB] Sql Code E xamples.. [DEV] All development stor...
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 | package step5; import java.util.Scanner; public class FuncHanSu { @SuppressWarnings("resource") public static void main(String[] args) { Scanner scan = new Scanner(System.in); //int valA = 110; int valA = scan.nextInt(); int valK = 0; int valHan = 0; int varArr[] = new int[3]; for(int i = 1; i <= valA; i++) { if(0 < i && i < 100) { valHan = i; } else if(i == 1000) { break; } else { valK = 0; int valT = i; while(valT > 0) { varArr[valK] = valT % 10; valT /= 10; valK++; } if(varArr[0] - varArr[1] == varArr[1] - varArr[2]) { valHan++; } } } System.out.println(valHan); } }// |
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 | package step5; //import java.util.Scanner; public class FuncNum { //@SuppressWarnings("resource") public static void main(String[] args) { //Scanner scan = new Scanner(System.in); int valA = 0; int valB = 0; int valC = 0; int valD = 0; int valResult = 0; boolean[] generator = new boolean[10000]; for(int i = 1; i < 10000; i++) { valA = i / 1000; valB = (i / 100) % 10; valC = (i / 10) % 10; valD = i % 10; //System.out.println("valA ######## > " + valA); //System.out.println("valB ######## > " + valB); //System.out.println("valC ######## > " + valC); //System.out.println("valD ######## > " + valD); //System.out.println("================================"); valResult = valA + valB + valC + valD + i; if((valResult >= 1) && (valResult < 10000)) { generator[valResult] = true; } } for(int i = 1; i < 10000; i++) { if(generator[i] == false) { System.out.println(i); } } } }// |
1 2 3 4 5 6 7 8 | Java package com.foo; public interface CheckingAccountService { public void cancelAccount(Long accountId); } |
1 2 3 4 5 6 7 8 9 10 | Java package com.foo; public class SimpleCheckingAccountService implements CheckingAccountService { public void cancelAccount(Long accountId) { System.out.println("Cancelling account [" + accountId + "]"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://ep-t43:61616"/> </bean> <bean id="queue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="mmm"/> </bean> </beans> |
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 | Xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="checkingAccountService" class="org.springframework.jms.remoting.JmsInvokerServiceExporter"> <property name="serviceInterface" value="com.foo.CheckingAccountService"/> <property name="service"> <bean class="com.foo.SimpleCheckingAccountService"/> </property> </bean> <bean class="org.springframework.jms.listener.SimpleMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory"/> <property name="destination" ref="queue"/> <property name="concurrentConsumers" value="3"/> <property name="messageListener" ref="checkingAccountService"/> </bean> </beans> Java package com.foo; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Server { public static void main(String[] args) throws Exception { new ClassPathXmlApplicationContext(new String[]{"com/foo/server.xml", "com/foo/jms.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 | Xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="checkingAccountService" class="org.springframework.jms.remoting.JmsInvokerProxyFactoryBean"> <property name="serviceInterface" value="com.foo.CheckingAccountService"/> <property name="connectionFactory" ref="connectionFactory"/> <property name="queue" ref="queue"/> </bean> </beans> Java package com.foo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Client { public static void main(String[] args) throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"com/foo/client.xml", "com/foo/jms.xml"}); CheckingAccountService service = (CheckingAccountService) ctx.getBean("checkingAccountService"); service.cancelAccount(new Long(10)); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Java String uri = "http://example.com/hotels/1/bookings"; PostMethod post = new PostMethod(uri); String request = // 예약 요청 내용 생성 post.setRequestEntity(new StringRequestEntity(request)); httpClient.executeMethod(post); if (HttpStatus.SC_CREATED == post.getStatusCode()) { Header location = post.getRequestHeader("Location"); if (location != null) { System.out.println("Created new booking at :" + location.getValue()); } } |
1 2 3 4 | Java String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class,"42", "21"); |
1 2 3 4 | Java Map<String, String> vars = Collections.singletonMap("hotel", "42"); String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/rooms/{hotel}", String.class, vars); |
1 2 3 4 5 6 7 8 9 | Java uri = "http://example.com/hotels/{id}/bookings"; RestTemplate template = new RestTemplate(); Booking booking = // 예약 객체 생성 URI location = template.postForLocation(uri, booking, "1"); |
1 2 3 4 5 6 7 | Java public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, String... urlVariables) // Map<String, String>처럼 urlVariables로 오버로드했다. |
1 2 3 4 5 | Java public interface RequestCallback { void doWithRequest(ClientHttpRequest request) throws IOException; } |
1 2 3 | Java restTemplate.getForObject("http://example.com/hotel list", String.class); |
1 2 3 4 5 6 7 8 | Java UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotels/{hotel}/bookings/{booking}").build() .expand("42", "21") .encode(); URI uri = uriComponents.toUri(); |
1 2 3 4 5 6 7 8 9 | Java UriComponents uriComponents = UriComponentsBuilder.newInstance() .scheme("http").host("example.com").path("/hotels/{hotel}/bookings/{booking}").build() .expand("42", "21") .encode(); URI uri = uriComponents.toUri(); |
1 2 3 4 5 6 7 8 9 10 11 | Java HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("MyRequestHeader", "MyValue"); HttpEntity< ?> requestEntity = new HttpEntity(requestHeaders); HttpEntity<String> response = template.exchange("http://example.com/hotels/{hotel}", HttpMethod.GET, requestEntity, String.class, "42"); String responseHeader = response.getHeaders().getFirst("MyResponseHeader"); String body = response.getBody(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | Java public interface HttpMessageConverter<T> { // 이 컨버터가 해당 클래스와 미디어타입을 읽을 수 있는지 여부를 나타낸다. boolean canRead(Class clazz, MediaType mediaType); // 이 컨버터가 해당 클래스와 미디어타입을 쓸(write) 수 있는지 여부를 나타낸다. boolean canWrite(Class clazz, MediaType mediaType); // 이 컨버터가 지원하는 MediaType 객체 목록을 반환한다. List<MediaType> getSupportedMediaTypes(); // 주어진 입력 메시지에서 해당 타입의 객체를 읽어서 반환한다. T read(Class<T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException; // 주어진 출력 메시지에 주어진 객체를 작성한다. void write(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException; } |