Spring整合Mybatis的简单示例(注解)

参考链接:Spring整合Mybatis的简单示例(配置文件)

1、创建数据库表

CREATE TABLE `t_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(12) DEFAULT NULL,
  `password` varchar(12) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

2、实体类、DAO接口

User.java

package com.yusian.entity;[......]

继续阅读

Spring工厂创建Bean的三种方式

1、@Component注解

  • 在相关类上加上@Component注解即可
  • 类名的小驼峰形式即为bean的id值
  • 该方式创建bean优先级最低
package com.yusian.entity;

import org.springframework.stereotype.Component;

@Component
public class User {

    private Integer id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {[......]

继续阅读