当前位置: 首页 > news >正文

springboot和mybatis项目学习

#项目整体样貌
在这里插入图片描述
##bean

package com.example.demo.bean;public class informationBean {private int id;private String name;private String password;private String attchfile;public int getId() {return id;}public String getName() {return name;}public String getPassword() {return password;}public String getAttchfile() {return attchfile;}
}
package com.example.demo.bean;public class UserInfo {private int id;private String name;private String password;private String attchfile;public int getId() {return id;}public String getName(){return name;}public String getPassword(){return password;}}

##controller

package com.example.demo.controller;import com.example.demo.bean.UserInfo;
import com.example.demo.bean.informationBean;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/test")
public class LoginController {//将Service注入Web层@AutowiredUserService userService;@ResponseBody@RequestMapping("/login")public String login(){return "login";}@ResponseBody@RequestMapping(value = "/loginIn")public informationBean loginIn(@RequestParam String name, @RequestParam String password){//UserBean userBean = userService.loginIn(name,password);informationBean userBean = userService.getInfore(name,password);if(userBean!=null){return userBean;}else {return null;}}@ResponseBody@RequestMapping("/getid")public UserInfo userId(Integer id) { // 使用实体类对象和接口方法if (id == null) {System.out.println("id is null");return null;}return userService.userId(id);}
}

##mapper

package com.example.demo.mapper;import com.example.demo.bean.informationBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;@Mapper
@Repository
public interface nameMapper {informationBean getInfo(@Param("name")String name, @Param("password")String password);
}
package com.example.demo.mapper;import com.example.demo.bean.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;@Mapper
@Repository
public interface UserMapper {UserInfo userId(@Param("id")Integer id);
}

##service接口和实现

package com.example.demo.service;import com.example.demo.bean.UserInfo;
import com.example.demo.bean.informationBean;public interface UserService {informationBean getInfore(String name, String password);UserInfo userId(Integer id);
}
package com.example.demo.ServiceImpl;import com.example.demo.bean.UserInfo;
import com.example.demo.bean.informationBean;
import com.example.demo.mapper.UserMapper;
import com.example.demo.mapper.nameMapper;
import com.example.demo.service.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;@MapperScan
@Service
public class UserServiceImpl implements UserService {//将DAO注入Service层@Autowiredprivate nameMapper a;public informationBean getInfore(String name, String password){System.out.println("userMapper.userId(id)");informationBean res = a.getInfo(name,password);if(res == null){System.out.println("userMapper.userId(id) is null");return null;}System.out.println("userMapper.userId(id)"+res.getId());return a.getInfo(name,password);}@Autowiredprivate UserMapper userMapper;public UserInfo userId(Integer id){ // 此处UserInfo为实体类对象,userId 为数据持久层接口方法System.out.println("public UserInfo userId(Integer id)");UserInfo RES = userMapper.userId(id);if(RES == null){return null;}//System.out.println("userMapper.userId(id)"+RES.getId());return RES; // 返回接口方法中的id,这里报错}}

#启动类

package com.example.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

##mapper

<?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.example.demo.mapper.nameMapper"><!--com.example.demo.bean.informationBean-->
<select id="getInfo" parameterType="String" resultType="informationBean">SELECT id,name,password,attchfile FROM password WHERE name = #{name} AND password = #{password}
</select></mapper>
<?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.example.demo.mapper.UserMapper"><!--com.example.demo.bean.informationBean--><select id="userId" parameterType="Integer"  resultType="UserInfo">SELECT id,name,password,attchfile FROM password WHERE id = #{id}</select></mapper>

##application.yml

server:port: 8080
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/firstdatabase?serverTimezone=GMT%2B8&useSSL=false&useUnicode=true&characterEncoding=utf-8username: rootpassword:
mybatis:type-aliases-package: com.example.demo.beanmapper-locations: classpath:mapper/*.xml

#pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.1</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>demo</description><properties><java.version>8</java.version><maven-jar-plugin.version>3.1.1</maven-jar-plugin.version></properties><dependencies><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.3.1</version></dependency><!--启动依赖3.0.3--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.22</version></dependency><!--    <dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency>--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!--<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.31</version><scope>runtime</scope></dependency>--></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><version>2.7.1</version><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

#效果
在这里插入图片描述

相关文章:

springboot和mybatis项目学习

#项目整体样貌 ##bean package com.example.demo.bean;public class informationBean {private int id;private String name;private String password;private String attchfile;public int getId() {return id;}public String getName() {return name;}public String getPas…...

simdjson 高性能JSON解析C++库

simdjson 是什么 simdjson 是一个用来解析JSON数据的 C 库&#xff0c;它使用常用的 SIMD 指令和微并行算法来每秒解析千兆字节的 JSON&#xff0c;在Velox, ClickHouse, Doris 中均有使用。 加载和解析 JSON documents 出于性能考虑&#xff0c;simdjson 需要一个末尾有几个…...

安卓Context上下文

目录 前言一、Context简介二、Application Context2.1 Application Context的创建过程2.2 Application Context的获取过程 三、Activity的Context创建过程四、Service的Context创建过程 前言 Context也就是上下文对象&#xff0c;是Android较为常用的类&#xff0c;但是对于Co…...

实验13 简单拓扑BGP配置

实验13 简单拓扑BGP配置 一、 原理描述二、 实验目的三、 实验内容四、 实验配置五、 实验步骤 一、 原理描述 BGP&#xff08;Border Gateway Protocol&#xff0c;边界网关协议&#xff09;是一种用于自治系统间的动态路由协议&#xff0c;用于在自治系统&#xff08;AS&…...

面试题分享--Spring02

Spring 框架中都用到了哪些设计模式?(必会) 1. 工厂模式&#xff1a;BeanFactory 就是简单工厂模式的体现&#xff0c;用来创建对象的实例 2. 单例模式&#xff1a;Bean 默认为单例模式 3. 代理模式&#xff1a;Spring 的 AOP 功能用到了 JDK 的动态代理和 CGLIB 字节码生成…...

基于QT和C++实现的中国象棋

一&#xff0c;源码 board.h #ifndef BOARD_H #define BOARD_H#include <QWidget> #include "Stone.h"class Board : public QWidget {Q_OBJECT public:explicit Board(QWidget *parent 0);bool _bRedTurn; // 红方先走int _currentPlayer; // 当前玩家&…...

Mojo崛起:AI-first 的编程语言能否成为新流行?

眨眼之间&#xff0c;你可能会错过又一种编程语言的发明。 有个笑话说&#xff0c;程序员花费20%的时间编写代码&#xff0c;80%的时间决定使用什么语言。 事实上&#xff0c;编程语言如此之多&#xff0c;以至于我们不确定实际有多少种。据估计&#xff0c;至少有700种编程语…...

【数据结构与算法】哈夫曼树与哈夫曼编码

文章目录 哈夫曼树&#xff08;最优二叉树&#xff09;定义举个&#x1f330;&#xff08;WPL的计算&#xff09; 哈夫曼树的构造&#xff08;最优二叉树的构造&#xff09;举个&#x1f330; 哈夫曼树的性质 哈夫曼编码定义构造 哈夫曼树&#xff08;最优二叉树&#xff09; …...

基于多头注意力机制卷积神经网络结合双向门控单元CNN-BIGRU-Mutilhead-Attention实现柴油机故障诊断附matlab代码

在使用这些深度学习库时&#xff0c;你可以按照以下步骤构建CNN-BIGRU-Multihead-Attention模型&#xff1a; 导入所需的库和模块。例如&#xff0c;在使用TensorFlow时&#xff0c;你可以导入tensorflow库和其他需要的模块。 定义输入层。根据你的数据&#xff0c;定义适当的…...

k8s redis 单节点部署

k8s redis 单节点部署kubectl 执行脚本 kubectl --kubeconfig ~/.kube-rz-real/config apply -f redis-leader.yaml -n rz-dt vi redis-leader.yamlapiVersion: apps/v1 kind: Deployment metadata:name: redis-leader-deploylabels:app: redisrole: leadertier: backend sp…...

科普童话投稿

《科普童话》杂志是由国家新闻出版总署批准、黑龙江省教育厅主管、黑龙江省语言文字报刊社主办的正规期刊。《科普童话》以培养科学素养与创新探索精神为办刊宗旨&#xff0c;以科学与艺术统一为编辑方针&#xff0c;以科学教育、教育科学作为自己的出发点&#xff0c;致力于对…...

【Ardiuno】使用ESP32单片机创建web服务通过网页控制小灯开关的实验(图文)

经过实验测试ESP32单片机的网络连接还是很方便的&#xff0c;这里小飞鱼按照程序实例的代码亲自实验一下使用Esp32生成的网页服务来实现远程无线控制小灯开关功能&#xff0c;这样真的是离物联网开发越来越近了&#xff0c;哈哈&#xff01; 连接好开发板和电路&#xff0c;将…...

百元蓝牙耳机哪款音质最好?四款实力超群机型推荐

在蓝牙耳机市场竞争日益激烈的今天&#xff0c;百元级别的耳机已经具备了令人瞩目的音质表现&#xff0c;对于追求高性价比的消费者来说&#xff0c;如何在众多选项中挑选出一款音质卓越的蓝牙耳机&#xff0c;无疑是一项重要而又充满挑战的任务&#xff0c;今天我将为大家推荐…...

Linux系统之mtr命令的基本使用

Linux系统之mtr命令的基本使用 一、mtr命令介绍二、mtr命令使用帮助2.1 mtr命令的帮助信息2.2 mtr帮助信息解释 三、安装mtr工具四、mtr命令的基本使用4.1 直接使用4.2 设定ping次数4.3 禁用DNS解析4.4 显示IP地址4.5 调整间隔 五、总结 一、mtr命令介绍 mtr命令是一个网络诊断…...

实战tcpdump4.99.4交叉编译

主要是记录交叉编译的一个坑&#xff0c;不知道为什么网上的教程都没遇到过。 环境 libpcap 1.10.4tcpdump 4.99.4WSL 编译步骤 注意事项 注意解压的时候文件夹名需要是libpcap-1.10.4&#xff0c;由于我是在github直接下载zip的压缩包名是libpcap-libpcap-1.10.4.tar.gz解…...

重生奇迹MU召唤术师简介

出生地&#xff1a;幻术园 性 别&#xff1a;女 擅 长&#xff1a;召唤幻兽、辅助魔法&攻击魔法 转 职&#xff1a;召唤巫师&#xff08;3转&#xff09; 介 绍&#xff1a;从古代开始流传下来的高贵的血缘&#xff0c;为了种族纯正血缘的延续及特殊使用咒术的天赋&…...

神经网络模型---AlexNet

一、AlexNet 1.导入tensorflow库&#xff0c;这里给简称为tf库 import tensorflow as tf from tensorflow.keras import datasets, layers, modelsdatasets&#xff1a;是用于训练和测试机器学习模型的数据集合 layers&#xff1a;是构建神经网络模型的关键组成部分 models&a…...

corona渲染器与vray比哪个好?支持云渲染平台吗

​在视觉渲染技术领域&#xff0c;V-Ray和Corona都以其卓越的性能和广泛应用赢得了高度评价。这两款渲染器各有其独特的优势&#xff0c;使得在它们之间做出选择并非易事。不同的应用场景和用户需求可能会让它们各自展现出不同的优势。 一、corona渲染器跟vray怎么样 在比较V-…...

每日一练:攻防世界:Ditf

这是难度1的题吗&#xff1f;&#xff1f;&#xff1f; 拿到一个png图片&#xff0c;第一反应就是CRC爆破&#xff0c;结果还真的是高度被修改了 这里拿到一个字符串&#xff0c;提交flag结果发现不是&#xff0c;那么只可能是密钥之类的了 看看有没有压缩包&#xff0c;搜索…...

约瑟夫环递归算法详解与实现

一、引言 约瑟夫环问题是一个著名的理论问题&#xff0c;其背景是在古罗马时期&#xff0c;有n个犯人被围成一个圈&#xff0c;从第一个人开始报数&#xff0c;每次报到m的人将被处决&#xff0c;然后从下一个人开始重新报数&#xff0c;直到所有人都被处决。这个问题可以用递…...

零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?

一、核心优势&#xff1a;专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发&#xff0c;是一款收费低廉但功能全面的Windows NAS工具&#xff0c;主打“无学习成本部署” 。与其他NAS软件相比&#xff0c;其优势在于&#xff1a; 无需硬件改造&#xff1a;将任意W…...

ServerTrust 并非唯一

NSURLAuthenticationMethodServerTrust 只是 authenticationMethod 的冰山一角 要理解 NSURLAuthenticationMethodServerTrust, 首先要明白它只是 authenticationMethod 的选项之一, 并非唯一 1 先厘清概念 点说明authenticationMethodURLAuthenticationChallenge.protectionS…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

pikachu靶场通关笔记22-1 SQL注入05-1-insert注入(报错法)

目录 一、SQL注入 二、insert注入 三、报错型注入 四、updatexml函数 五、源码审计 六、insert渗透实战 1、渗透准备 2、获取数据库名database 3、获取表名table 4、获取列名column 5、获取字段 本系列为通过《pikachu靶场通关笔记》的SQL注入关卡(共10关&#xff0…...

如何在网页里填写 PDF 表格?

有时候&#xff0c;你可能希望用户能在你的网站上填写 PDF 表单。然而&#xff0c;这件事并不简单&#xff0c;因为 PDF 并不是一种原生的网页格式。虽然浏览器可以显示 PDF 文件&#xff0c;但原生并不支持编辑或填写它们。更糟的是&#xff0c;如果你想收集表单数据&#xff…...

OD 算法题 B卷【正整数到Excel编号之间的转换】

文章目录 正整数到Excel编号之间的转换 正整数到Excel编号之间的转换 excel的列编号是这样的&#xff1a;a b c … z aa ab ac… az ba bb bc…yz za zb zc …zz aaa aab aac…; 分别代表以下的编号1 2 3 … 26 27 28 29… 52 53 54 55… 676 677 678 679 … 702 703 704 705;…...

【Veristand】Veristand环境安装教程-Linux RT / Windows

首先声明&#xff0c;此教程是针对Simulink编译模型并导入Veristand中编写的&#xff0c;同时需要注意的是老用户编译可能用的是Veristand Model Framework&#xff0c;那个是历史版本&#xff0c;且NI不会再维护&#xff0c;新版本编译支持为VeriStand Model Generation Suppo…...

Ubuntu系统多网卡多相机IP设置方法

目录 1、硬件情况 2、如何设置网卡和相机IP 2.1 万兆网卡连接交换机&#xff0c;交换机再连相机 2.1.1 网卡设置 2.1.2 相机设置 2.3 万兆网卡直连相机 1、硬件情况 2个网卡n个相机 电脑系统信息&#xff0c;系统版本&#xff1a;Ubuntu22.04.5 LTS&#xff1b;内核版本…...

高考志愿填报管理系统---开发介绍

高考志愿填报管理系统是一款专为教育机构、学校和教师设计的学生信息管理和志愿填报辅助平台。系统基于Django框架开发&#xff0c;采用现代化的Web技术&#xff0c;为教育工作者提供高效、安全、便捷的学生管理解决方案。 ## &#x1f4cb; 系统概述 ### &#x1f3af; 系统定…...

[USACO23FEB] Bakery S

题目描述 Bessie 开了一家面包店! 在她的面包店里&#xff0c;Bessie 有一个烤箱&#xff0c;可以在 t C t_C tC​ 的时间内生产一块饼干或在 t M t_M tM​ 单位时间内生产一块松糕。 ( 1 ≤ t C , t M ≤ 10 9 ) (1 \le t_C,t_M \le 10^9) (1≤tC​,tM​≤109)。由于空间…...