Skip to content

Instantly share code, notes, and snippets.

donchan922 donchan922

Block or report user

Report or block donchan922

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View DemoMapper.java
@Mapper
public interface DemoMapper {
@Select("SELECT * FROM USER WHERE id = #{id}")
User findById(@Param("id") String id);
}
View Demo.java
@MapperScan("com.example.demo") // 不要
@SpringBootApplication
public class DemoApplication {
// ...
}
View Mockito.java
List mockedList = mock(List.class);
Mockito.doNothing().doNothing().doThrow(new RuntimeException()).when(mockedList).clear();
mockedList.clear();
mockedList.clear();
mockedList.clear(); // RuntimeException発生
View Mockito.java
List mockedList = mock(List.class);
Mockito.when(mockedList.get(0))
.thenReturn("one")
.thenReturn("two")
.thenThrow(new RuntimeException());
System.out.println(mockedList.get(0)); // one
System.out.println(mockedList.get(0)); // two
System.out.println(mockedList.get(0)); // RuntimeExceptionが発生する
View Mockito.java
List mockedList = mock(List.class);
// 基本形
Mockito.when(mockedList.get(0))
.thenReturn("one")
.thenReturn("two")
.thenReturn("three");
// 短縮形
Mockito.when(mockedList.get(0)).thenReturn("one", "two", "three");
View DemoApplication.java
public class DemoApplication {
public static void main(String[] args) throws IOException {
CsvMapper mapper = new CsvMapper();
// ヘッダあり
CsvSchema schema = mapper.schemaFor(User.class).withHeader();
Path path = Paths.get("CSVファイルのパス");
try (BufferedReader br = Files.newBufferedReader(path)) {
View DemoApplication.java
public class DemoApplication {
public static void main(String[] args) throws IOException {
CsvMapper mapper = new CsvMapper();
// ヘッダなし
CsvSchema schema = mapper.schemaFor(User.class);
Path path = Paths.get("CSVファイルのパス");
try (BufferedReader br = Files.newBufferedReader(path)) {
View no_header
001,Alice,18
002,Bob,25
003,Carol,23
View User.java
// CSVの各項目を読み込む順序を設定する
@JsonPropertyOrder({"id", "name", "age"})
public class User {
private String id;
private String name;
private int age;
public User(String id, String name, int age) {
this.id = id;
You can’t perform that action at this time.