从零开始学习springBoot(myqsl链接+端口修改+jpa映射)

1.修改端口号:在application.properties文件添加:server.port=9090   就能将端口号修改为9090

2.连接数据库:

2.1:修改pom.xml  添加

2.2:application.properties文件添加:

  ########################################################
  ###datasource
  ########################################################
  spring.datasource.url = jdbc:mysql://localhost:3306/fy
  spring.datasource.username = root
  spring.datasource.password = root
  spring.datasource.driverClassName = com.mysql.jdbc.Driver
  spring.datasource.max-active=20
  spring.datasource.max-idle=8
  spring.datasource.min-idle=8
  spring.datasource.initial-size=10


  ########################################################
  ### JPA
  ########################################################
  # Specify the DBMS
  spring.jpa.database = MYSQL
  spring.jpa.show-sql = true
  spring.jpa.hibernate.ddl-auto = update
  spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

3.添加dao接口

4.编写service类

5.写一个controller类

6.访问http://127.0.0.1:9090/demo2/save

7.数据库会保存一条数据

学习来源http://412887952-qq-com.iteye.com/blog/2291542
原文地址:https://www.cnblogs.com/zhengzhouyang/p/7700186.html