首页 > 其他 > 详细

mybatis练习1

时间:2020-01-12 14:43:15      阅读:69      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 1.建表

USE how2java;

CREATE TABLE product (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(32) DEFAULT NULL,
price float(8) default 0.0,
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

USE how2java;
INSERT INTO product VALUES (001,‘computer‘,3700.0);

技术分享图片

 

 

2.编写对应pojo和配置文件xml

技术分享图片

 

 

package com.how2java.pojo;

public class Product {
    int id;
    String name;
    float price;
    public Product(int id, String name, float price) {
        super();
        this.id = id;
        this.name = name;
        this.price = price;
    }
    public Product() {
        super();
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    @Override
    public String toString() {
        return "Product [id=" + id + ", name=" + name + ", price=" + price + "]";
    }
}

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
    <mapper namespace="com.how2java.pojo">
        <select id="listProduct" resultType="Product">
            select * from product     
        </select>
    </mapper>

 

 

3.编写测试文件并测试

技术分享图片

mybatis练习1

原文:https://www.cnblogs.com/roof/p/12182600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!