(IDEA+Spring boot)
1.創(chuàng)建springboot 項(xiàng)目.(選擇web項(xiàng)即可)。
2.配置application.properties
server.port=8080
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/(數(shù)據(jù)庫名稱)?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
3.配置pom.xml
添加以下依賴
4.創(chuàng)建student類
@Entity
public class Student {
@Id
@GeneratedValue
? ? private Longid;
? ? private Stringname;
? ? private Longage;
? ? private Integersex;
? ? public LonggetId() {
return id;
? ? }
public void setId(Long id) {
this.id = id;
? ? }
public StringgetName() {
return name;
? ? }
public void setName(String name) {
this.name = name;
? ? }
public LonggetAge() {
return age;
? ? }
public void setAge(Long age) {
this.age = age;
? ? }
public void setSex(Integer sex) {
this.sex = sex;
? ? }
public IntegergetSex() {
return sex;
? ? }
}
5.創(chuàng)建StudentRepository
@Repository
public interface StudentRepositoryextends CrudRepository {
StudentfindStudentById(Long id);
}
6.然后就可以去創(chuàng)建controller 增刪改查啦蝶押!
代碼:https://github.com/mengdongdong/springboot.git