build.gradle
plugins { id 'org.springframework.boot' version '2.1.6.RELEASE' id 'java' }
apply plugin: 'io.spring.dependency-management'
group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8'
repositories { mavenCentral() }
dependencies { compile('org.springframework.boot:spring-boot-starter-thymeleaf') compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('mysql:mysql-connector-java') compile('org.projectlombok:lombok') implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' }
User.java
package com.example.study.model.entity;
//import com.example.study.model.enumclass.UserStatus; import lombok.*; import lombok.experimental.Accessors; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedBy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import java.time.LocalDateTime; import java.util.List;
@Data @AllArgsConstructor @NoArgsConstructor @Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String account;
private String email;
private String phoneNumber;
private LocalDateTime createdAt;
private String createdBy;
private LocalDateTime updatedAt;
private String updatedBy;
}
UserRepositoryTest.java
package com.example.study.repository;
import com.example.study.StudyApplicationTests; import com.example.study.model.entity.User;
import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime; import java.util.Optional;
public class UserRepositoryTest extends StudyApplicationTests {
//Dependency Injection(DI)
@Autowired
private UserRepository userRepository;
@Test
public void create(){
User user=new User();
user.setAccount("TestUser01");
user.setEmail("[email protected]");
user.setPhoneNumber("010-1111-1111");
user.setCreatedAt(LocalDateTime.now());
user.setCreatedBy("TestUser01");
User newUser=userRepository.save(user);
System.out.println("newUser:"+newUser);
userRepository.flush();
}
@Test
public void read(){ Optional user=userRepository.findById(2L);
user.ifPresent(selectUser->{
System.out.println("user:"+user);
});
}
public void update(){
}
public void delete(){
}
}
Error message
Testing started at 8:09 AM ...
Task :cleanTest UP-TO-DATE Task :compileJava UP-TO-DATE Task :processResources UP-TO-DATE Task :classes UP-TO-DATE Task :compileTestJava FAILED /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:22: error: cannot find symbol user.setAccount("TestUser01"); ^ symbol: method setAccount(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:23: error: cannot find symbol user.setEmail("[email protected]"); ^ symbol: method setEmail(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:24: error: cannot find symbol user.setPhoneNumber("010-1111-1111"); ^ symbol: method setPhoneNumber(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:25: error: cannot find symbol user.setCreatedAt(LocalDateTime.now()); ^ symbol: method setCreatedAt(LocalDateTime) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:26: error: cannot find symbol user.setCreatedBy("TestUser01"); ^ symbol: method setCreatedBy(String) location: variable user of type User 5 errors FAILURE: Build failed with an exception.
It pops up like this. And I put in the WICODE as it was from Pacam, but it doesn't work;;; I did the same while watching the lecture
spring-boot
I'd rather ask a question to Pacam.
First, remove @Data
annotation and implement getter/setter for each variable in the User class and test it.
For example...Implement for all instance variables as follows.
...
public String getAccount() {
return account;
}
public void setAccount(String account){
this.account = account;
}
...
© 2024 OneMinuteCode. All rights reserved.