backend09
@Data
student
package cn.lnfvc;
import cn.lnfvc.pojo.Student;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
Student student=new Student();
student.setId(100);
System.out.println(student.getId());
}
}
TestController.java
跨域
package cn.lnfvc.controller;
import cn.lnfvc.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
@RestController
public class TestController {
@Autowired
private JdbcTemplate jdbcTemplate;
@CrossOrigin
@RequestMapping("/loadStudent")
public List loadStudent() {
String sql = "select * from students";
List stus=jdbcTemplate.query(sql, new RowMapper() {
@Override
public Student mapRow(ResultSet rs, int i) throws SQLException {
Student student =new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setGender(rs.getBoolean("gender"));
return student;
}
});
return stus;
}
}
Student.java(用@Data代替getter and setter)
package cn.lnfvc.pojo;
import lombok.Data;
@Data
public class Student {
private Integer id;
private String name;
private boolean gender;
}