1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| package com.example.jpaorm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.List;
@SpringBootApplication public class JpaormApplication implements CommandLineRunner {
public static void main(String[] args) { SpringApplication.run(JpaormApplication.class, args); }
@Autowired UserRep userRep;
@Override public void run(String... args) throws Exception { User user = new User(); user.setName("babb"); user.setAge(11); userRep.save(user);
List<User> users = userRep.findByName("babb"); System.out.println(users);
List<User> users2 = userRep.findByNameNativeQuery("babb"); System.out.println(users2); }
}
|