Skip to content

Instantly share code, notes, and snippets.

View A-pZ's full-sized avatar

A-pZ A-pZ

  • Capybara(Oni-Tenjiku-nezumi)
  • Tokyo, shinagawa
View GitHub Profile
@A-pZ
A-pZ / CSVDataSetLoader.java
Last active April 6, 2022 02:19
TestDatabaseConfig
package com.github.apz.sample.mapper;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.csv.CsvDataSet;
import org.springframework.core.io.Resource;
import com.github.springtestdbunit.dataset.AbstractDataSetLoader;
public class CSVDataSetLoader extends AbstractDataSetLoader {
@Override
protected IDataSet createDataSet(Resource resource) throws Exception {
return new CsvDataSet(resource.getFile());
}
@A-pZ
A-pZ / ItemMapperDBUnitTest.java
Last active April 6, 2022 02:15
ItemMapperDBUnitTest
package com.github.apz.sample.mapper;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
@A-pZ
A-pZ / ItemMapper.java
Created April 6, 2022 02:12
ItemMapper
package com.github.apz.sample.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.github.apz.sample.record.Item;
@Mapper
public interface ItemMapper {
public List<Item> findById(@Param("id") String id);
}
@A-pZ
A-pZ / TaskSchedulerService.java
Created June 1, 2021 06:21
SchedLock execution method sample
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.github.apz.repository.TaskRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
@Service
@A-pZ
A-pZ / SchedulerSampleApplication.java
Created June 1, 2021 06:15
Enable ShedLock Setting
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
@SpringBootApplication
@EnableScheduling
// EnableSchedulerLockの属性値に指定する時間フォーマットはjava.time.Durationを利用。
// https://en.wikipedia.org/wiki/ISO_8601#Durations
// MostForはロック時間の最長。LeastFor は ロック時間の最短。
@EnableSchedulerLock(defaultLockAtMostFor = "PT5M", defaultLockAtLeastFor = "PT30S")
@A-pZ
A-pZ / SchedulerSampleApplication.java
Created June 1, 2021 06:12
Spring Scheduler Setting
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class SchedulerSampleApplication {
public static void main(String[] args) {
SpringApplication.run(SchedulerSampleApplication.class, args);
}
}
@A-pZ
A-pZ / delete.html
Created March 20, 2021 07:42
これで正しく読み込まれているかと思います
<!DOCTYPE html>
<html lang="ja"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<title>削除画面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta charset="UTF-8"/>
<link th:href="@{/css/common.css}" rel="stylesheet"/>
<link th:href="@{/webjars/bootstrap/4.6.0-1/css/bootstrap.min.css}" rel="stylesheet" />
@A-pZ
A-pZ / WebConfig.java
Created October 21, 2020 13:00
こうした上で、クエリ文字列に language=言語(JP)などを入れないと、クッキーに出力されない。
import javax.servlet.ServletContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
@A-pZ
A-pZ / ArrayListAction.java
Last active December 16, 2019 04:53
Struts2.3~で表形式の入出力を行う(JSP編)
/**
*
*/
package com.github.apz.struts2.sample.arrays.actions;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
@A-pZ
A-pZ / TextArea.java
Last active July 30, 2019 09:57
ThymeleafのDiarectサンプル:TextAreaに入力された改行つきテキストを HTMLのbreakをつけて出力する
package com.github.apz.config;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.springframework.util.StringUtils;
public class TextArea {
final static String LINE_SEPARATOR = "\r\n";