spring에서 이전페이지로 복귀는 request의 referer를 이용해서 가능하다.


이전 페이지에 추가적인 데이타를 보내고 싶다면

addFlashAttribute로 가능하다. 


import javax.servlet.http.HttpServletRequest;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

String myFunction(HttpServletRequest request,
RedirectAttributes redirectAttributes,
) {

redirectAttributes.addFlashAttribute("okList", "AA BB CC");

String referer = request.getHeader("Referer");
return "redirect:"+ referer;
}


Posted by yongary
,

MEAN, LAMP & Others

IT 2017. 3. 16. 18:30

LAMP stack: Linux, Apache, MySql, PHP (Perl/Python)

  REF

MEAN stack: MongoDB, ExpressJS, AngularJS, NodeJS

         - ExpressJS:  Node.js Web application framework. 

         - NodeJS: event-driven I/O server-side JavaScript Environment.




Play-framework :  Scala & java 용 프레임워크.  REF

- 이게 spring처럼 널리 이용된다면 scala도 그만큼 역량을 키워가겠네요.  

- JSON과 xml을 First-class 고객으로 모시는 프레임워크인만큼 계속 영향력이 커지지 않을까요..










Posted by yongary
,

bootstrap을 이용해서 table도 쉽고 이쁘게 만들 수 있지만

팝업도 간단히 이쁘게 만들 수 있다.


게다가 팝업이 약간씩 멋지게 움직이는 효과도 있어 심미적으로 만족감도 상당하다.


팝업은 modal ( 팝업이 뜨면서 팝업안에서만 작업이 되는 팝업을 일컫는 단어) 을 이용하면 되고

팝업이 나타나면서 움직이는 효과는 aria-hidden을 이용하면 된다..  REF



bootstrap.min.css  LINK 및 

bootstrap.min.js 정도추가하면 되고.. 및


modal DIALOG의 구조는 아래와 같은 구조.

<div class="modal fade" role="dialog" aria-hidden="true">

<div class="modal-dialog" role="document">
<div class="modal-content">

<div class="modal-header">
<div class="modal-body"> 
<div class="modal-footer">



TEXT Color

<p class="text-muted">...</p> //grey
<p class="text-primary">...</p> //light blue
<p class="text-success">...</p> //green
<p class="text-info">...</p> //blue
<p class="text-warning">...</p> //orangish,yellow
<p class="text-danger">...</p> //red


Posted by yongary
,

웹상에서 간단히 날짜 선택창을 만들고 싶다면

jQuery의 DatePicker모듈을 이용하는 것이 좋아 보인다.


REF   (우측 상단에 예제 있음)



TimePicker도 시간입력용으로 좋은데,

시간을 step단위로 지정이 가능하다.  REF


var timeFix;

function timeFixClick(minutes) {
timeFix.val(minutes);
$('#timeModal').modal('show');
}

$(document).ready(function () {
timeFix = $('#timeFix');

datePicker.datepicker({
format: "yyyy-mm-dd",
viewMode: "days",
minViewMode: "days",
});

timePicker.timepicker();
timePicker.timepicker('option', 'step', '30'); //30분 단위로 시간 선택가능.

<html>

<input name="expireTime" class="form-control" data-time-format="H:i:s" id="timePicker" type="text" size="8" />
<a th:onclick="'javascript:timeFixClick(\'' + ${ticket.minutes} + '\');'" th:text="修正" />



<js 시간 Library> -   REF: https://momentjs.com/



  <script type="text/javascript" th:src="@{js/moment.min.js}"></script>  한 후에..


(사용 예)

  var date = moment(dateData).format('YYYY-MM-DD');

  var time = moment(dateDate).format('HH:mm:ss');


Posted by yongary
,

Jms + ActiveMQ

Spring 2017. 3. 13. 16:34

spring에서 msg를 전달하는 가장 흔한 방법은

JMS(+jmsTemplate)과 ActiveMQ(by apache)를 이용하는 방법이다. 물론 ASYNC 메시징이다.


ActiveMQ를 사용하고자 하면, ActiveMQConnectionFactory가 JMSConnectionFactory로써 제공된다.


 -디폴트 포트: 61616 



<Send>

ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616";

Connection conn = cf.createConnection();


session = conn.createSession(..);


MessageProducer producer = session.createProducer(destination);


producer.send( session.createTextMessage('hello')..)




<Receive>

MessageConsumer consumer = session.createConsumer(destination);
Message message = consumer.receive();



<JmsTemplate을 사용하면 좀더 간단해진다>


jmsOperations.send( new MessageCreator() { ......blabla }

또는 컨버팅 필요시

 

jmsOperations.convertAndSend


Posted by yongary
,

REF


위의 REF를 참조해서 아래와 같이 string으로 변경하면

mySql에서 바로 사용이 가능하다. 



Clock clock;

DateTimeFormatter DB_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

String alarmTime = dateTime.format(DB_TIME_FORMAT);



String alarm2 = LocalDateTime.now(clock).format(DB_TIME_FORMAT)


그리고, LocalDateTime을 바로 MySQL에 저장도 가능한데.. (음 이게 더 나아보인다)


단, 이때 String 을  LocalDateTime으로 변환필요시가 있을때에는

"yyyy-MM-ddTHH:mm:ss") 형태를 사용해야 한다.   ( T가 중요)

Posted by yongary
,

몇몇 Annotation

Spring 2017. 3. 9. 18:48

 @ModelAttribute on a method argument -  indicates the argument will be retrieved from the model. If not present in the model, the argument will be instantiated first and then added to the model.


@Retryable (a.Exception, b.Exception 지정가능. 미지정시 상시.. )


@Recover (a.Exception) : a.Exception으로 실패시에에만 호출되어서.. 특별한 뒷처리 및 로그작업등 가능.



@Component( name부여가능 )


@Profile("profile_name")  - name에 해당하는 profile이 active일 때만, Bean이 생성됨. dev test등 주로 이용.


@Conditional - 조건부 Bean생성. 


@GatherJob    (USER_Defined)

  - 나중에 모으고 싶은 것들을 임의로 선언한다. (class는 있어야 죠 , 간단한 빈깡통 Interface면 됨.)

Set<Class<?>> gather = New Reflections(My.class.getPackage().getName())

.getTypesAnnotatedWith(GatherJob.class);


@Qualifier("my name") - 

Posted by yongary
,

REF


Mokito의 ArgumentCaptor를 사용해, insert/update같은 동작을 간단하게  hooking할 수 있다.


(예제)

final ArgumentCaptor<Ticket> logCaptor = ArgumentCaptor.forClass(Ticket.class);
verify(chatTicketRepository).update(logCaptor.capture());
Ticket ticket = logCaptor.getValue();

assertThat(ticket.getStatus(), is(TicketStatus.EXPIRED));



좀 더 복잡한 경우는, ArgumentMatcher를 이용해 복잡한 비교를 할 수 있다. 



파라미터를 hooking하는 다른방법: REF

when(mockObject.myMethod(any(parameterClass.class))).thenAnswer(
                invocation -> invocation.getArgumentAt(0, parameterClass.class));


Posted by yongary
,

MySQL 시간 비교

BACK-END 2017. 3. 2. 16:30

REF


시간비교시에는 MySQL의 INTERVAL 을 이용하는 것이 가장 편한 것으로 보인다.


예)

WHERE

myTable.datetimefield > now() - INTERVAL 3 DAY (or MONTH or WEEK ) 

==> 그러나, 날짜간에는 빼기 보다는  DATE_SUB를 사용해야 하고.


BETWEEN도 사용이 가능하지만,.. 작은 날짜를 앞에 써야 한다.

WHERE my_date BETWEEN DATE_SUB(now(), INTERVAL 1 WEEK) AND now()

참) 그리고 NULL을 비교할때는,  IS NULL   또는  IS NOT NULL 을 사용해야 한다.



그 외 Doma라는 ORM에서 IF와 같이 쓰는 경우엔 다음과 같이 섞어서 사용할 수도 있다.

service.service_code
/*%if sortKey == @com.linecorp.fortune.constant.ServiceSortKey@NEW */
, IF ( NOW() - INTERVAL 1 WEEK < forum_service.published_at, 1, 0) as is_new
/*%elseif sortKey == @com.linecorp.fortune.constant.ServiceSortKey@ANSWER_TIME */
, IF (forum_service_condition.average_answer_time = 0, 12, forum_service_condition.average_answer_time) as answer_time
/*%end*/


Posted by yongary
,

스프링으로 주기적으로 도는 함수를 만들고 싶으면... 


아주 간단하게


public 함수위에 

@Scheduled(cron = "0 39 */2 * * *")와 같이 선언하면 된다.



아래는 매일 2시 49분에 도는 함수!


@Scheduled(cron = "0 49 2 * * *")

참고:  제일앞자리는 cron에 없는거네요.. 용도는?  초.   */30 이러면 매 30초마다임.  REF

   

초 0-59 , - * / 

분 0-59 , - * / 

시 0-23 , - * / 

일 1-31 , - * ? / L W

월 1-12 or JAN-DEC , - * / 

요일 1-7 or SUN-SAT , - * ? / L # 

년(옵션) 1970-2099 , - * /

* : 모든 값

? : 특정 값 없음

- : 범위 지정에 사용

, : 여러 값 지정 구분에 사용

/ : 초기값과 증가치 설정에 사용

L : 지정할 수 있는 범위의 마지막 값

W : 월~금요일 또는 가장 가까운 월/금요일

# : 몇 번째 무슨 요일 2#1 => 첫 번째 월요일



<cron 은    REF 참조>


crontab 파일 형식
------    --------  ---------------------------------------------------
필  드    의  미    범  위
------    --------  ---------------------------------------------------
첫번째    분        0-59
두번째    시        0-23
세번째    일        0-31
네번째    월        1-12
다섯번째  요일      0-7 (0 또는 7=일요일, 1=월, 2=화,...)
여섯번째  명령어    실행할 명령을 한줄로 쓴다.
------    --------  ---------------------------------------------------


예) 5  */2 *  *  * 명령어 => 매일 2시간간격으로 5분대에 

Posted by yongary
,