I've touched java, When I look at the source code that includes the framework \ (^ O ^) / <"What's this?" And I often stopped, so I just wrote a memo.
What is equivalent to ** DAO ** (Data Access Object) in Java In Spring, it's called the ** Repository class **.
What makes the ** Repository class ** convenient (easy) to use It's a library called ** Spring Data JPA **.
Immediately, the code below is for "getting the employee name".
EmployeeRepository.java
@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService{
@Autowired
EmployeeRepository employeeRepository;
public Employee getName(String name) {
return Employee employee = employeeRepository.findByName(name);
}
}
And it is possible to get the employee name from the database with the following simple code. For me, who knew only PureJava, I thought, "What? That's it?"
EmployeeRepository.java
@Repository("EmployeeRepository")
public interface EmployeeRepository extends JpaRepository<Employee, String>{
public Employee findByName(String Name);
}
In the above ** Repository class **, the following steps are performed. "Get the exact match from the Employee table that matches the string specified in the field named name."
To summarize briefly, -Capitalize the first field name you want to search -Define methods for specific formats such as findBy ~ Only these two points are done without leaking, and JPA, which is a library, automatically implements the processing after ! </ font> I want to try database access for the time being! Those who say need verification.
Originally, you should know how to write it if you look at the document. It is a document with high hurdles for those who are just starting to learn, with words that have never been seen in a specialized way. ** ** I felt that only those who were familiar with the framework could read it. It will take several months to read with accurate conviction, as you will have to look up the meaning of the word.
Recommended Posts