本文共 4303 字,大约阅读时间需要 14 分钟。
4.0.0 com.wo vue_first 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-test mysql mysql-connector-java org.springframework.boot spring-boot-starter-data-jpa org.projectlombok lombok true
server: port: 8080spring: datasource: driver-class-name: com.mysql.jdbc.Driver username: root password: 123456 url: jdbc:mysql://localhost:3306/qf?useUnicode=true&characterEncoding=utf8&useSSL=false jpa: database: MYSQL generate-ddl: true show-sql: true
@RestControllerpublic class StudentController { @Autowired StudentService studentService; @RequestMapping("/findAll") public ListfindAll(){ return studentService.findAll(); } @RequestMapping("/saveAndUpdate") public String saveAndUpdate(@RequestBody TbStudent tbStudent){ try { studentService.saveAndUpdateStudent(tbStudent); }catch (Exception ex){ return "fail"; } return "success"; } @RequestMapping("/findById") public TbStudent findById(@RequestBody Map map){ String id = (String) map.get("id"); return studentService.findById(Integer.valueOf(id)); } @RequestMapping("/del") public void del(@RequestBody Map map){ Integer id = (Integer) map.get("id"); studentService.deleteById(Integer.valueOf(id)); }}
public interface StudentRespository extends JpaRepository{ }
@Data@Entity@Table(name = "Tb_sys_student")public class TbStudent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id ; private String name; private Integer age; private Integer sex; private String address;}
public interface StudentService { ListfindAll(); TbStudent findById(Integer id); void saveAndUpdateStudent(TbStudent tbStudent); void deleteById(Integer integer);}
@Servicepublic class StudentServiceImpl implements StudentService { @Autowired StudentRespository studentRespository; @Override public ListfindAll() { return studentRespository.findAll(); } @Override public TbStudent findById(Integer id) { return studentRespository.findById(id).get(); } @Override public void saveAndUpdateStudent(TbStudent tbStudent) { studentRespository.saveAndFlush(tbStudent); } @Override public void deleteById(Integer integer) { studentRespository.deleteById(integer); }}
@SpringBootApplicationpublic class VueApplication { public static void main(String[] args) { SpringApplication.run(VueApplication.class); }}
Title
序号 学生姓名 学生年龄 学生性别 学生住址 操作 { { index+1}} { { student.name}} { { student.age}} { { student.sex==0?'女':'男'}} { { student.address}}
Title
Title
转载地址:http://tcezi.baihongyu.com/