对数据的基本操作是必然的,springboot的几个,我就给大家讲讲我在实战的时候所遇到的坑。
Javabean
package com.taopan.bean;
public class StudentGrade {
private int gradeid;
private int studentid;
private String studentname;
private String studentclass;
private int gradec;
private int gradejava;
private int gradejavaweb;
public int getGradeid() {
return gradeid;
}
public void setGradeid(int gradeid) {
this.gradeid = gradeid;
}
public int getStudentid() {
return studentid;
}
public void setStudentid(int studentid) {
this.studentid = studentid;
}
public String getStudentname() {
return studentname;
}
public void setStudentname(String studentname) {
this.studentname = studentname;
}
public String getStudentclass() {
return studentclass;
}
public void setStudentclass(String studentclass) {
this.studentclass = studentclass;
}
public int getGradec() {
return gradec;
}
public void setGradec(int gradec) {
this.gradec = gradec;
}
public int getGradejava() {
return gradejava;
}
public void setGradejava(int gradejava) {
this.gradejava = gradejava;
}
public int getGradejavaweb() {
return gradejavaweb;
}
public void setGradejavaweb(int gradejavaweb) {
this.gradejavaweb = gradejavaweb;
}
@Override
public String toString() {
return "StudentGrade{" +
"gradeid=" + gradeid +
", studentid=" + studentid +
", studentname='" + studentname + '\'' +
", studentclass='" + studentclass + '\'' +
", gradec=" + gradec +
", gradejava=" + gradejava +
", gradejavaweb=" + gradejavaweb +
'}';
}
}
1、@select
查全表
@Select("select * from studentgrade ")
public List queryGrade();
有条件查询
@Select("select * from studentgrade where gradeid=#{gradeid}")
public StudentGrade queryOne(@Param("gradeid") int gradeid);
查总数
@Select("select count(1) from account")
public int querySize();
模糊查询
@Select("select * from studentgrade where studentname like #{name} or studentclass like #{name} ")
public List selectMohu(@Param("name") String name);
分页查询:
@Select("select * from studenttest limit #{pageno},#{pageSize}")
public List query(@Param("pageno") int pageno, @Param("pageSize")int pageSize);
2、删除
@Delete("delete from studentgrade where gradeid=#{gradeid} ")
public int delete(@Param("gradeid") int gradeid);
3、插入
@Insert("insert into studentgrade values(#{studentgrade.gradeid},#{studentgrade.studentid},#{studentgrade.studentname},#{studentgrade.studentclass},#{studentgrade.gradec},#{studentgrade.gradejava},#{studentgrade.gradejavaweb})")
public int insert(@Param("studentgrade") StudentGrade studentGrade);
4、更新
@Update("update studentgrade set studentid=#{studentgrade.studentid},studentname=#{studentgrade.studentname},studentclass=#{studentgrade.studentclass},gradec=#{studentgrade.gradec},gradejava=#{studentgrade.gradejava},gradejavaweb=#{studentgrade.gradejavaweb} where gradeid=#{studentgrade.gradeid}")
public int update1(@Param("studentgrade")StudentGrade studentgrade);
这个文件里面的方法名不能相同!!我吃了这个亏。