mybatis参数深入

mybatis参数深入_第1张图片
这种可以随便写

mybatis参数深入_第2张图片
mybatis会在实体类中找对应的属性 所以这个值要跟对象里面的属性值一样

如果实体类的属性名称和数据库中的名称不一样可以配置对应属性映射

package com.wsp.dao;

import com.wsp.domain.user;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserDao {


    @Select("select * from user")
    @Results(id="resultMap",value = {
            @Result(id = true,column = "id",property = "userId"),
            @Result(column = "username",property = "userName"),
            @Result(column = "address",property = "userAddress"),
            @Result(column = "sex", property = "userSex"),
            @Result(column = "birthday", property = "userBirthday")


    })
    List<user> findAll();

    @Select("select * from user where id=#{id}")
    user findById(Integer id);

    @Select("select * from user where username like #{username}")
    List<user> findByName(String username);

    @Insert("insert into user(username,address,sex,birthday)values(#{userName},#{userAddress},#{userSex},#{userBirthday})")
    void saveUser(user user);

    @Update("update user set username=#{userName},address=#{userAddress} where id=#{userId}")
    void updateById(user user);

    @Delete("delete from user where id=#{userId}")
    void deleteUser(Integer id);



}

但是同样这些名称还是要与实体类保持一致
在这里插入图片描述

你可能感兴趣的:(java框架,mybatis)