Skip to content
Snippets Groups Projects
Commit aa7d2edb authored by 채원 임's avatar 채원 임
Browse files

0326

parent 0b72e9a7
Branches
No related tags found
No related merge requests found
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping(value = "/test")
public UserDto test(){
UserDto dto = new UserDto();
dto.setAge(17);
dto.setName("Jane");
return dto;
}
}
package com.example.demo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class UserDto {
private String name;
private Integer age;
}
package com.example.demo.constant;
public enum ItemSellStatus {
SELL, SOLD_OUT
}
package com.example.demo.entity;
import com.example.demo.constant.ItemSellStatus;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.time.LocalDateTime;
import javax.persistence.*;
import org.springframework.stereotype.Component;
@Table(name="item")
@Getter
@Setter
@ToString
@Entity
public class Item {
@Id
@Column(name="item_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, length= 50)
private String itemNm;
@Column(name="price", nullable = false)
private int price;
@Column(nullable = false)
private int stockNumber;
@Lob
@Column(nullable = false)
private String itemDetail;
@Enumerated(EnumType.STRING)
private ItemSellStatus itemSellStatus;
private LocalDateTime regTime;
private LocalDateTime updateTime;
}
package com.example.demo.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import com.example.demo.entity.Item;
// @NoRepositoryBean
public interface ItemRepository extends JpaRepository<Item, Long>{
}
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.show_sql = true
spring.application.name=demo
server.port = 3000
\ No newline at end of file
server.port = 3000
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/shop?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=web1
# spring.datasource.driver-class-name=org.h2.Driver
# spring.datasource.url=jdbc:h2:mem:test
# spring.datasource.username=sa
# spring.datasource.password=
# spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.show_sql = true
spring.jpa.properties.hibernate.connection.autocommit = true
spring.jpa.properties.hibernate.format_sql = true
logging.level.org.hibernate.type.descriptor.sql = trace
package com.example.demo.repository;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import com.example.demo.entity.Item;
//import com.example.demo.entity.QItem;
import org.junit.jupiter.api.DisplayName;
import java.time.LocalDateTime;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.junit.runner.RunWith;
import com.example.demo.constant.ItemSellStatus;
import java.util.List;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.querydsl.jpa.impl.JPAQuery;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@SpringBootTest
@TestPropertySource(locations="classpath:application-test.properties")
@RunWith( SpringJUnit4ClassRunner.class )
public class ItemRepositoryTest {
@Autowired
ItemRepository itemRepository;
@Test
@DisplayName("상품 저장 테스트")
public void createItemTest(){
Item item = new Item();
item.setItemNm("테스트 상품");
item.setPrice(100000);
item.setItemDetail("테스트 상품 상세 설명");
item.setStockNumber(100);
item.setRegTime(LocalDateTime.now());
item.setUpdateTime(LocalDateTime.now());
Item savedItem = itemRepository.save(item);
System.out.println(savedItem.toString());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment