发表于: 2022-04-20 19:11:05
1 537
重新学习配置了jdbctemplate添加配置了部分applicationContext.xml文件
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="root"></property>
<property name="password" value="密码"></property>
<property name="url" value="jdbc:mysql://localhost:3306/newtest"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
代码测试结果
之后尝试在接口与实现中添加部分代码片段来执行。
执行结果:
使用BeanPropertyRowMapper字段包装数据库中要使用的类型:
代码片段:
package test;
import org.springframework.jdbc.core.RowMapper;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Biage implements Serializable {
private static final long serialVersionUID = -7850272141987310060L;
private int id;
private String school;
private String name;
private String type;
private String time;
private String student;
private String make_a_wish;
public String getMake_a_wish() {
return make_a_wish;
}
public void setMake_a_wish(String make_a_wish) {
this.make_a_wish = make_a_wish;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getStudent() {
return student;
}
public void setStudent(String student) {
this.student = student;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Biage{" +
"id=" + id +
", school='" + school + '\'' +
", name='" + name + '\'' +
'}';
}
}
执行的结果:
使用Mybatis的时为什么不需要Impl:
jdk为你的接口手动生成了一个实现了对应接口的类,因此,你的接口可以调用,简称:jdk代理。
尝试编写了一个Junit单元测:
执行结果:
评论