当前位置:Gxlcms > 数据库问题 > mybatis-04(使用annotation完成对sql的获取)

mybatis-04(使用annotation完成对sql的获取)

时间:2021-07-01 10:21:17 帮助过:2人阅读

configuration> <properties resource="db.properties"/> <typeAliases> <!-- 两种方法随便用,建议用第二种 --> <!--<typeAlias type="com.huawei.bean.Student" alias="Student"/>--> <package name="com.huawei.bean"/> </typeAliases> <environments default="development"> <environment id="development"> <!-- 配置事务 --> <transactionManager type="JDBC" /> <!-- 配置数据库连接信息 --> <dataSource type="POOLED"> <property name="driver" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </dataSource> </environment> </environments> <mappers> <mapper class="com.huawei.mapper.StudentMapper"/> </mappers> </configuration>

StudentMapper.java文件

package com.huawei.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import com.huawei.bean.Student;

public interface StudentMapper {
    @Insert("insert into student (id,name,grade,classname) values(seq_student_id.nextval,#{name},#{grade},#{className})")
    public void add(Student bean);
    
    @Select("select id as id ,name as name,grade as grade, classname as className from student")
    public List<Student> getStudents();
    
}

项目结构

技术分享

 

mybatis-04(使用annotation完成对sql的获取)

标签:

人气教程排行