상세 컨텐츠

본문 제목

스프링부트2 가지고 놀기

JSP·자바·코틀린

by 김일국 2019. 12. 11. 15:31

본문

스프링부트2에서 CRUD 연습을 해 보았습니다.

작업소스: H2 메모리DB를 이용, Maven컴파일 사용.

boot-spring-boot.zip

원본소스: https://github.com/ihoneymon/boot-spring-boot

Ps1. 위 소스에서 사용된 랜덤변수 사용방법

       /*
       Random rnd = new Random();
        //영소문자 a-z 출력하기 (아스키코드 97~122)
        String randomStr = String.valueOf((char) ((int) (rnd.nextInt(26)) + 97));
        //영대문자 A-Z 출력하기 (아스키코드 65~122)
        String randomStr = String.valueOf((char) ((int) (rnd.nextInt(26)) + 65));
        //숫자 0-9 출력하기
        String randomStr = String.valueOf(rnd.nextInt(10));
       //아래 부터는 pom.xml에 정의한 andomStringUtils클래스 사용
       System.out.println("Default     [" + RandomStringUtils.random(10) + "]");
       System.out.println("CustomChar  [" + RandomStringUtils.random(10, new char[]{'A','B','C'}) + "]");
       System.out.println("CustomString[" + RandomStringUtils.random(10, "ABC") + "]");
       System.out.println("Alphabetic  [" + RandomStringUtils.randomAlphabetic(10) + "]");
       System.out.println("Alphanumeric[" + RandomStringUtils.randomAlphanumeric(10) + "]");
       System.out.println("Ascii       [" + RandomStringUtils.randomAscii(10) + "]");
       System.out.println("Numeric     [" + RandomStringUtils.randomNumeric(10) + "]");
       */
       String randomStr = RandomStringUtils.random(10, "abc") + "@gmail.com";
       String password = RandomStringUtils.randomNumeric(10);
       User user = new User(randomStr, password);
       try {service.adduser(user);} catch (Exception e) {e.printStackTrace();}
       List<User> list = service.findAll();
       for (Object item : list) {
        //System.out.println(item.toString());
        log.info(item.toString());
       }

Ps2. 다음 포스트에서는 Maven이 아닌, Gradle기반으로 컴파일 할 예정입니다.

이클립스(STS플러그인)에서 Gradle 프로젝트로 임포트해서 사용하거나, 또는 IntelliJ Community Free버전 개발환경 에서 작업예정임.

boot-spring-boot.zip
0.14MB

관련글 더보기

댓글 영역