Created
September 18, 2016 17:31
-
-
Save arahansa/931d36ea657f890696f13cceb9e544f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.springboot.mybatis.xmlconfig.service; | |
import java.util.Date; | |
/** | |
* Sample DTO | |
* | |
* @author sbcoba | |
* | |
*/ | |
public class Member { | |
private Long id; | |
private String name; | |
private String phone; | |
private Date creationtime; | |
public Long getId() { | |
return id; | |
} | |
public void setId(Long id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getPhone() { | |
return phone; | |
} | |
public void setPhone(String phone) { | |
this.phone = phone; | |
} | |
public Date getCreationtime() { | |
return creationtime; | |
} | |
public void setCreationtime(Date creationtime) { | |
this.creationtime = creationtime; | |
} | |
@Override | |
public String toString() { | |
return "Member [id=" + id + ", name=" + name + ", phone=" + phone + "]"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE MEMBER ( | |
ID int(11) NOT NULL, | |
NAME varchar(50) DEFAULT NULL, | |
PHONE varchar(20) DEFAULT NULL, | |
CREATIONTIME datetime DEFAULT CURRENT_TIMESTAMP, | |
PRIMARY KEY (ID) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.springboot.mybatis.xmlconfig; | |
import lombok.extern.slf4j.Slf4j; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.SpringApplicationConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import org.springframework.test.context.web.WebAppConfiguration; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | |
import org.springframework.web.context.WebApplicationContext; | |
import sample.springboot.mybatis.xmlconfig.service.Member; | |
import sample.springboot.mybatis.xmlconfig.service.MemberMapper; | |
import java.time.LocalDateTime; | |
import java.time.temporal.ChronoUnit; | |
import java.util.List; | |
import java.util.Map; | |
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | |
/** | |
* Created by jarvis on 2016. 9. 19.. | |
*/ | |
@Slf4j | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = SampleApplication.class) | |
@WebAppConfiguration | |
public class MybatisDataTest { | |
@Autowired | |
WebApplicationContext wac; | |
MockMvc mockMvc; | |
@Autowired | |
MemberMapper memberMapper; | |
@Before | |
public void init() { | |
mockMvc = MockMvcBuilders.webAppContextSetup(wac) | |
.alwaysDo(print()) | |
.build(); | |
memberMapper.deleteMember(); | |
for (Long i=0L; i<1000;i++){ | |
Member member = new Member(); | |
member.setId(Long.valueOf(i)); | |
member.setName("member"+i); | |
member.setPhone("member"+i); | |
memberMapper.saveMember(member); | |
} | |
} | |
static LocalDateTime before, after; | |
@Test | |
public void strTest() throws Exception{ | |
before = LocalDateTime.now(); | |
final List<Map<String, String>> allString = memberMapper.findAllString(); | |
after = LocalDateTime.now(); | |
log.info("all Map : {}", allString); | |
long betweenString = ChronoUnit.MILLIS.between(before, after); | |
log.info("MapStr Between : {}", betweenString); | |
} | |
@Test | |
public void objTest() throws Exception{ | |
before = LocalDateTime.now(); | |
final List<Member> all = memberMapper.findAll(); | |
log.info("all : {}", all); | |
after = LocalDateTime.now(); | |
long between = ChronoUnit.MILLIS.between(before, after); | |
log.info("Member Between : {}", between); | |
} | |
@Test | |
public void mapTest() throws Exception{ | |
before = LocalDateTime.now(); | |
final List<Map<String, Object>> allMap = memberMapper.findAllMap(); | |
after = LocalDateTime.now(); | |
log.info("all Map : {}", allMap); | |
long betweenMap = ChronoUnit.MILLIS.between(before, after); | |
log.info("MapObj Between : {}", betweenMap); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MapObj Between : 24 | |
MapStr Between : 53 | |
Member Between : 178 | |
MapObj Between : 204 | |
MapStr Between : 276 | |
Member Between : 744 | |
MapObj Between : 177 | |
MapStr Between : 363 | |
Member Between : 779 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment