String boot <3> mysql
来源:互联网 发布:看演唱会软件 编辑:程序博客网 时间:2024/05/16 06:52
pom.xml 要添加MySQL jap 、mysql、web
package com.java1234;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name="book")public class Books {@Id@GeneratedValueprivate int id;@Column(length=100)private String name;@Column(length=50)private String author;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}}一、声明实体
@Entity
对实体注释。任何Hibernate映射对象都要有这个注释
@Table
声明此对象映射到数据库的数据表,通过它可以为实体指定表(talbe),目录(Catalog)和schema的名字。该注释不是必须的,如果没有则系统使用默认值(实体的短类名)。
package com.java1234.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import com.java1234.Books;import com.java1234.dao.Bookdao;@Controller@RequestMapping("books")public class bookcontrpoller {@Resourceprivate Bookdao bookdao;@RequestMapping("/list")public ModelAndView list() {ModelAndView mav = new ModelAndView();mav.addObject("bookslist", bookdao.findAll());mav.setViewName("booklist");return mav;}@RequestMapping(value="/addbook",method=RequestMethod.POST)public String addbook(Books book) {bookdao.save(book);return "forward:/books/list";}@RequestMapping("/perupdata/{id}")public ModelAndView perupdata(@PathVariable("id") Integer id) {System.out.println("id:"+id);ModelAndView mav = new ModelAndView();mav.addObject("bookslist", bookdao.getOne(id));mav.setViewName("updatal");return mav;}@GetMapping(value="delete")/**@postMapping**/public String delete(Integer id) {System.out.println("id:"+id);ModelAndView mav = new ModelAndView();bookdao.delete(id);return "forward:/books/list";}}
application.properties文件改为application.yml 更有层次感server: port: 80 context-path: /spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/book username: root password: 123456 jpa: hibernate: ddl-auto: update show-sql: true
阅读全文
0 0
- String boot <3> mysql
- Spring Boot(3)-使用mysql
- String Boot 的入门
- String Boot 学习笔记(二)
- MYSQL STRING
- spring boot + gradle + mysql
- spring boot设定mysql
- spring boot mysql配置
- Spring boot结合Mysql
- spring-boot集成mysql
- spring boot String类型json 存入数据库
- 2、Spring boot 集成 mysql
- Spring Boot Mysql 数据库操作
- Spring Boot 使用mysql数据库
- Spring boot MySQL Access denied
- Spring Boot实战【mysql安装】
- SpringBoot:spring boot mysql配置
- Spring boot操作mysql数据库
- 图像的复原与重建(3):图像去噪(中值、均值、谐波均值、自适应、带通、带阻、陷波滤波器)
- day3上午模拟赛
- 怎么用IDEA上传本地项目到码云/Github?
- caffe 容易犯的错误
- 这 8 份「Paper + Code」,你一定用得上 | PaperDaily #08
- String boot <3> mysql
- 简化顺序表运算
- Leetcode 算法题01
- 查找一个文件的硬链接,文件后缀名,文件长度及文件名的限制
- Swift 4.0 数组(Array)之过滤器(filter)的使用
- 我对KMP算法的理解
- Java敏感词过滤
- MySQL存储过程
- 初步认识Spring-boot