码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis练习1

时间:2020-01-12 14:58:20      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:测试文件   utf-8   img   varchar   not   技术   arc   get   图片   

技术图片

 

 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

标签:测试文件   utf-8   img   varchar   not   技术   arc   get   图片   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!