首页 > 其他分享 >9.20

9.20

时间:2024-12-26 13:30:24浏览次数:2  
标签:username mapper 9.20 ParameterMapper sqlSession user import

mybatis的应用能大大简化我们编写程序的代码并提升效率。

复制代码
package com.aurora.mybatis.test;

import com.aurora.mybatis.mapper.ParameterMapper;
import com.aurora.mybatis.pojo.User;
import com.aurora.mybatis.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class ParameterMapperTest {

    @Test
    public void testGetAllUser(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        List<User> list = mapper.getAllUser();
        list.forEach(user -> System.out.println(user));
    }
    @Test
    public void testGetUserByUsername(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        User admin = mapper.getUserByUsername("admin");
        System.out.println(admin);
    }
    @Test
    public void testCheckLogin(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        User user = mapper.checkLogin("admin","123456");
        System.out.println(user);
    }
    @Test
    public void testCheckLoginByMap(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        Map<String , Object> map = new HashMap<>();
        map.put("username","admin");
        map.put("password","123456");
        User user = mapper.checkLoginByMap(map);
        System.out.println(user);
    }
    @Test
    public void testInsertUser(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        int result = mapper.insertUser(new User(null, "李四", "123", 23, "男", "123@qq.com"));
        System.out.println(result);
    }
    @Test
    public void testCheckLoginByParam(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
        User user = mapper.checkLoginByParam("admin","123456");
        System.out.println(user);
    }
}
复制代码

xml

复制代码
<?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.aurora.mybatis.mapper.ParameterMapper">
    <!--List<User> getAllUser();-->
    <select id="getAllUser" resultType="User">
        select * from t_user
    </select>
<!--    User getUserByUsername(String username);-->
    <select id="getUserByUsername" resultType="User">
        select * from t_user where username = #{username}
    </select>
<!--    User checkLogin(String username,String password);-->
    <!-- arg0 arg1 param1 param2-->
    <select id="checkLogin" resultType="User">
        select * from t_user where username= #{arg0} and password = #{arg1}
    </select>
<!--    User checkLoginByMap(Map<String, Objects> map);-->
    <select id="checkLoginByMap" resultType="User">
        select * from t_user where username= #{username} and password = #{password}
    </select>
<!--    int insertUser(User user);-->
    <insert id="insertUser">
        insert into t_user values(null,#{username},#{password},#{age},#{sex},#{email})
    </insert>
<!--User checkLoginByParam(@Param("username") String username, @Param("password") String password);-->
    <select id="checkLoginByParam" resultType="User">
        select * from t_user where username= #{username} and password = #{password}
    </select>
</mapper>

标签:username,mapper,9.20,ParameterMapper,sqlSession,user,import
From: https://www.cnblogs.com/kongxiangzeng/p/18632550

相关文章

  • 【2024潇湘夜雨】WIN10_Pro_22H2.19045.4955软件选装纯净特别版9.20
    【系统简介】=============================================================1.本次更新母盘来自WIN10_Pro_22H2.19045.4955.2.全程离线精简、无人值守调用优化处理制作。部分优化适配系统可能要重启几次,即使显示适配失败也不要在意,可能部分优化不适用。3.OS版本号为19045.4955。......
  • java学习9.20
    今天是简单的java小测验,实现简单的增删改查操作。我先用数组完成。后面的话想实现连接数据库的增删改查,但是始有bug不知道咋改,写的少不清楚问题出在哪,多写几回应该就能对症下药。下面是数组的代码Student类publicclassStudent{Stringstunumber;Stringname;......
  • 9.20 模拟赛
    C.[CSP-S--三十连测第二十七套]--T3--fac-S---【云智计划】---6月30日---模拟测#27div2【补题】-比赛-梦熊联盟(mna.wang)题意\(n\)次询问,给定\(a,k\)。有一个可重集合,初始只有一个元素\(a\)。每次操作将集合中所有元素替换为它的所有约数。求\(k\)次操作后集......
  • 9.20 斜率优化复习
    看我之前写的狗屎:https://www.becoder.com.cn/article/11836。当时根本就不懂斜率优化是什么。今天真的懂了,来写总结。1问题转化对于一类dp方程式:\(f(i)=\min\{f(j)+A(j)*g(i)+B(j)+t(i)\}\)。可以用斜率优化。设\(b=f(i)-t(i)\)。把当前dp转移当成是一条斜率......
  • 活动召集丨实时多模态 AI Builder 团聚!RTE Open Day@S创上海,9.20/21
       9月20~21日,上海,S创上海2024,看见不一样的创新和技术。 这场年轻、多元、活力十足的科技盛会,将汇聚创业者、开发者、艺术家和众多无法定义边界的跨界者。RTE开发者社区的Builders和RTEOpenDay也将玩乐其中! 「有一群人在一起,就很好」。来到第四期的RTE......
  • Cisco Secure Firewall 4200 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布
    CiscoSecureFirewall4200SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-4200/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSe......
  • Cisco Secure Firewall 3100 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布
    CiscoSecureFirewall3100SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:CiscoSecureFirewall3100SeriesFTDSoftware7.4.2&ASASoftware9.20.3,查看最新版。原创作品,转载请......
  • Cisco Firepower 9300 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布下载 -
    CiscoFirepower9300SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-9300/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSecure......
  • Cisco Firepower 4100 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布下载 -
    CiscoFirepower4100SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-4100/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSecure......
  • Cisco Firepower 2100 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布下载 -
    CiscoFirepower2100SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-2100/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSecure......