实体类
@Entity
@Table(name = "user")
class User {
@Id var host: String? = null
@Column(name="user") var user: String? = null
@Column(name="selectPriv") var selectPriv: String? = null
@Column(name="insertPriv") var insertPriv: String? = null
@Column(name="updatePriv") var updatePriv: String? = null
}
dao接口
interface UserRepository : JpaRepository<User, Long>
controller
@Controller
class Use{
@Autowired
private val userRepository: UserRepository? = null
@GetMapping("test1")
fun test(model:Model):String{
model.addAttribute("op",userRepository?.findAll())
return "index"
}
}
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/mysql
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent-output=true