하나의 html페이지로 Listing과 Editing을 동시에 수행하는 페이지는 다음과 만들 수 있다.

(참고:  jQuery와 themeleaf이용)

 

포인트: flag(isEditMode)를 두어서 list인지 Edit인지를 구분하고, 

 그에 따라 필요한 버튼을 hide/show

 input을 readonly or not 으로 세팅한다. 


<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
$(function () {
allReload();

//list-edit Mode switch
function allReload() {
if ($('#isEditMode').val() == 'true'){
$('.form-control').prop('readonly', false);
$('.form-control').css('border', '1px solid #ccc');
$('#editBtn').hide();
$('#storeBtn').show();
$('#cancelBtn').show();
} else {
$('.form-control').prop('readonly', true);
$('.form-control').css('border', 'none');
$('#editBtn').show();
$('#storeBtn').hide();
$('#cancelBtn').hide();
}
}

$('#editBtn').click(function () {
$('#isEditMode').val('true');
allReload();
});

$('#cancelBtn').click(function () {
$('#isEditMode').val('false');
allReload();
});
//Button process


});
/*]]>*/
</script>
<input type="hidden" id="isEditMode" th:value="${isEditMode}"/>

<form id="form" method="post" enctype="multipart/form-data" th:object="${chatRankingCoefficientForm}"
action="/app/chat/ranking/constant">
<table class="table table-hover table-bordered"
style="word-break: break-all;word-wrap: break-word;" border="1">
<tr>
<th style="text-align:center">ranking</th>
<th style="text-align:center">Value</th>
</tr>
<tr>
<td>Days of Evaluation</td>
<td>
<input class="form-control" readonly="true" style="border:none;background-color:transparent;"
type="number" th:field="*{daysOfEvaluation}"/>
<div th:classappend="${#fields.hasErrors('daysOfEvaluation')} ? 'has-error'">
<span th:if="${#fields.hasErrors('daysOfEvaluation')}" th:errors="*{daysOfEvaluation}"
class="help-block">error!</span>
</div>
</td>
</tr> ..중략

<p> <!-- BUTTONS -->
<a class="btn btn-primary" id="editBtn">edit</a>
<input type="submit" class="btn btn-primary" id="storeBtn" value="save" />
<a th:href="@{/app/chat/ranking/constant}" class="btn btn-secondary" id="cancelBtn">cancel</a>
</p>
</form>


Posted by yongary
,

개발의 편의상 spring-boot-devtools라는 걸 사용하는게 좋다. REF

아래와 같은 5가지 기능이 지원된다.



Automatic Restart


LiveReload 

  - 특히 이부분은 개발을 할 때는 편하나, cache(@Cacheable)가 바뀌어도 자동 reload해주는 등 편하지만

    개발환경에서 ClassCastException이 발생할 수 있다.

    즉, cache에서 복원된 Object가 Class로 변환이 잘 안되는 문제가 있다.


   그래서 Cache를 테스트할 때는, 이부분을 pom.xml등에서  코멘트아웃을 하고 하는게 좋다.



Remote Debug Tunneling


Remote update and restart


Video Privew


Posted by yongary
,

cookie 와 JSESSIONID

FRONT-END 2017. 5. 18. 12:11

브라우저에서 쿠키를 이러저러 여러가지 값으로 설정할 수 있는데 REF

 
Tomcat의 경우는 

JSESSIONID 변수를 쿠키로 주고받으면서 세션을 유지한다.  REF


웹서버마다 방식이나 변수명이 다르므로 확인이 필요하다. 

nginx웹서버의 경우 cc변수로 보인다. 



현재쿠키는 javascirpt:document.cookie  를 주소창에 치면 쉽게 확인할 수 있다.


쿠키를 조작해서 테스트하고 싶을때는 postman , 그 중에서도 postman intercepter를 크롬에 설치하면 가능하다. 

Posted by yongary
,

mysql 원격copy

BACK-END 2017. 5. 17. 12:09

옆동료에게 나의 db를 그대로 복사해주고 싶은 경우,


일단 원격 접속을 해야하기 때문에

1.  mysql> grant all privileges on *.* to 'root'@'10.33.%';   동료pc에서 이런식으로 접속 허용을 해준다.


2. $ mysqldump -u root databaseName > temp.sql

3. 동료 mysql에 접속한 후 ( $mysql -h 동료pc_IP  -u root ) 아래명령 실행.

   mysql> create database databaseName

   mysql> use dataBaseName

   mysql> source temp.sql




Posted by yongary
,

Builder 와 Factory

java core 2017. 5. 9. 23:20

Builder는 간단히 말하면 setter가 다 끝나고 생성자를 호출해 주는 패턴이다. 

개념은 간단한데 왜 필요한가에 대한 답은 :  복잡한 생성자와 복잡한 setter가 섞여있는 경우 유용하다. REF 

예) PersonInfo personInfo = new Builder("Mommoo").setAge(12).setPhonNumber(119).build( );

 

Factory는 여러개의 subClass가 있을경우 생성자가 각각 생기는 복잡한 문제가 있는데..

이를 하나의 생성자로 통일해 주는 큰 장접이 있다.   REF

 

 

Posted by yongary
,

@Bean 사용법

Spring 2017. 5. 8. 14:19

@Autowired 를 사용할 경우에는 classpath내에 존재해야 하는데,

그게 여의치 않거나 새로운 생성자가 필요한 경우에는


생성자를 직접 정의하면서 @Bean을 사용할 수 있다. 


1.정의시:


@Configuration

public class OkHttpClientConfig {

@Bean(name = CHAT_BILLING_HTTP_CLIENT)

OkHttpClient chatBillingHttpClient() {

OkHttpClient client = new OkHttpClient();

client.setTimeOut(blabla)


return client;

}



2.사용시:


@Qualifier(OkHttpClientConfig.CHAT_BILLING_HTTP_CLIENT)

@Autowired

OkHttpClient chatBillingHttpClient;




Posted by yongary
,


REF



mySql에 dateTime을 지정해서 입력하는 경우,


STR_TO_DATE('12-01-2014 00:00:00','%m-%d-%Y %H:%i:%s') 을 사용해서 insert할 수도 있지만

아래와 같이 간단히 숫자로도 가능하다. 



insert into campaign(campaign_code,version,memo,start_at,end_at,created_at,updated_at) values('bogo',1,'test',20170509150000,20170511110000,now(),now());

Posted by yongary
,

Worker Thread 패턴

java core 2017. 4. 27. 15:19

REF

 

제한된 thread개수를 이용하여 여러개의 작업을 하고 싶을때 Worker Thread와 Pool을 이용하면 된다.

 

REF:myBlog

Posted by yongary
,

각종 DB에러 exception

BACK-END 2017. 4. 25. 16:57

여러가지 DB 관련된 에러를 포함하는 java exception은  DataAccessException으로 보인다.


http://helols.tistory.com/12  

Posted by yongary
,

Regex

java core 2017. 4. 20. 18:28

내가 많이 쓰는 간단한 방식은

String pattern = "[Tt]he";                                          // [A-Za-z]   \\s \\w \\d

boolean matched = "the".matches(pattern);  //=> true : 시작^ 끝$까지 포함해서정확히 일치해야 함.

(참고: https://codechacha.com/ko/java-regex/)

 

알파벳/숫자/언더바만 포함되었는지 체크하려면..
String pattern = "^[\\w]*$";
boolean a = "abc123".matches(pattern);

 

알파벳/숫자 만 체크하려면..
String pattern = "^[a-zA-Z0-9]*$";
boolean a = "abc123".matches(pattern);

 

그룹에서 \1 즉 "\\1"은 첫번째 엘리먼트를 뜻함. = m.group(1)
\\b (바운더리) 는 이스케이프 캐릭터로서 단어를 찾을때 앞뒤에 넣으면 좋음.

중복된 단어 하나로 만들기 예제
        // String regex = "\\b(\\w+)\\b(?=.*\\b\\1\\b)";
        // String regex = "(\\b\\w+)(\\W\\1\\b)+";
        
        //이것도 잘되나 String regex = "\\b(\\w+)(\\s\\1)+\\b";
        String regex = "(\\w+)(\\s\\1)+"; //이게 제일 심플하면서 어느정도 동작 확인. 
          //스페이스 제외하고 앞부분만을 word로 보는듯. 
        
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);

            String input = in.nextLine();
            
            Matcher m = p.matcher(input);
           
            // Check for subsequences of input that match the compiled pattern
            while (m.find()) {
                //  System.out.println("==" + m.group() + "," + m.group(1)+".");
                input = input.replaceAll(m.group() , m.group(1));
            }
            // Prints the modified sentence.
            System.out.println(input);

 

Regex Test 사이트는  https://regex101.com/

 

java API:  https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html 

Regex자료는 여기서 참고: Ref

 

표현식  설명 
 ^  문자열의 시작,   [^a-z] 에서는 NOT의 의미로 쓰임.
 문자열의 종료
 .  임의의 한 문자 (문자의 종류 가리지 않음)
 단, \ 는 넣을 수 없음
 *  앞 문자가 없을 수도 무한정 많을 수도 있음
 앞 문자가 하나 이상
 앞 문자가 없거나 하나있음
 []  문자의 집합이나 범위를 나타내며 두 문자 사이는 - 기호로 범위를 나타낸다. []내에서 ^가 선행하여 존재하면 not 을 나타낸다.
 {}  횟수 또는 범위를 나타낸다. =>   {1,3} 콤마를 써야 함.
 ()  소괄호 안의 문자를 하나의 문자로 인식 
 |  패턴 안에서 or 연산을 수행할 때 사용
 \s  공백 문자
 \S  공백 문자가 아닌 나머지 문자
 \w  알파벳이나 숫자 (언더바도 체크함)
\W   알파벳이나 숫자를 제외한 문자
\d   숫자 [0-9]와 동일
\D   숫자를 제외한 모든 문자
 정규표현식 역슬래시(\)는 확장 문자
 역슬래시 다음에 일반 문자가 오면 특수문자로 취급하고 역슬래시 다음에 특수문자가 오면 그 문자 자체를 의미
(?i)   앞 부분에 (?i) 라는 옵션을 넣어주면 대소문자를 구분하지 않음

▲ 출처 : http://lng1982.tistory.com/141

 

 

 

Posted by yongary
,