入口 springboot
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
public class Demo2Application {
public static void main(String[] args) {
SpringApplication.run(Demo2Application.class, args);
}
}
测试代码 字符串导进去的时候 public 能输入进去 导进去的时候,private 识别不了为null
package com.example.demo.controller;
import com.example.demo.Entity.Author;
import com.example.demo.Mapper.AuthorDaoImpl;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
private AuthorDaoImpl authorDao;
@RequestMapping(value = "/hello")
public String hello(){
System.out.println(111);
return "hello springboot!";
}
@PostMapping("/insert")
public Boolean add(@RequestBody Author author) {
authorDao= new AuthorDaoImpl();
return authorDao.insertAuthor(author);
}
}
author.java
package com.example.demo.Entity;
public class Author {
public Integer author_id;
public String author_name;
public String author_discription;
public Integer getAuthor_id() {
return author_id;
}
public Author(Integer author_id, String author_name, String author_discription) {
this.author_id = author_id;
this.author_name = author_name;
this.author_discription = author_discription;
}
public void setAuthor_id(Integer author_id) {
this.author_id = author_id;
}
public String getAuthor_name() {
return author_name;
}
public void setAuthor_name(String author_name) {
this.author_name = author_name;
}
public String getAuthor_discription() {
return author_discription;
}
public void setAuthor_discription(String author_discription) {
this.author_discription = author_discription;
}
// 此处省略set、get和toString方法
}