数据库:
表:
数据:
存储过程:
添加依赖:
创建 log4j.properties:
创建 vo 类:
创建接口:
insert into `student`(`id`,`name`,`mobile`,`address`) values ('059ba7c5-34d4-48bf-9e76-13f52a95e229','萧婷','13031070239','新疆自治区乌鲁木齐市沙依巴克区雅玛里克山街道新疆三建
家属院'),('0cc9987d-1c75-415c-8c37-e5000b202286','韦傲然','17194017474','辽宁省沈阳市皇姑区蓝天家园');
delimiter $$
create procedure pro_student(in i_id varchar(36), out o_name varchar(18), out o_mobile varchar(11) , out o_address varchar(150))
begin
select name, mobile, address into o_name, o_mobile, o_address from student where id = i_id;
end $$
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
log4j.rootLogger=debug,console,file
#输出到控制台
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %d{MM-dd HH:mm:ss,SSS} %m (%F:%L)
#输出到文件
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=D:\log4j.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p %d{MM-dd HH:mm:ss,SSS} %m (%F:%L)
#SQL 语句
log4j.logger.com.mybatis=DEBUG
log4j.logger.com.mybatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.mybatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
package com.soft.vo;
public class Student {
private String id;
private String name;
private String mobile;
private String address;
...省略 setter 和 getter...
@Override
public String toString() {
return "Student{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", mobile='" + mobile + '\'' +
", address='" + address + '\'' +
'}';
}
}
package com.soft.student.dao;
import com.soft.vo.Student;
public interface IStudentDao {
void getById(Student student);//
注意:没有返回值
}
CREATE TABLE `student` (
`id` char(36) NOT NULL COMMENT '主键',
`name` varchar(18) NOT NULL COMMENT '姓名',
`mobile` char(11) NOT NULL COMMENT '手机号',
`address` varchar(150) NOT NULL COMMENT '家庭地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE DATABASE test CHARACTER SET utf8;
评论0