接口的讲解

您所在的位置:网站首页 cameralink接口协议 接口的讲解

接口的讲解

2024-07-12 18:07:24| 来源: 网络整理| 查看: 265

在这里之前我想童鞋们都学习过了springmvc。mybatis-plus。Springboot等一些框架

那么下面我们就整合这些框架

我们通过写crud这些接口

写接口的第一步就是引入pom文件 在pom文件里引入一下几种依赖

引入父级工程 thymeleaf导入模版工具类 SpringMVCjar包文件 热部署工具 lombok插件 测试包 引入jdbc包 引入数据库驱动 spring整合mybatis-plus 负责项目打包部署

4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.5 jiekou 1.0-SNAPSHOT 16 16 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime com.baomidou mybatis-plus-boot-starter 3.4.2 org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok org.apache.maven.plugins maven-compiler-plugin 16 16 pom文件引入依赖之后那么下一步就需要配置数据库 的连接以及我们配置的端口 server: port: 8090 spring: datasource: url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true username: root password: wyproot123 #整合SpringMVC thymeleaf: #设置页面前缀 prefix: classpath:/templates/ #设置页面后缀 suffix: .html #是否使用缓存 cache: false mybatis-plus: type-aliases-package: com.jt.pojo #type-aliases-package: com.jt mapper-locations: classpath:/mappers/*.xml #开启驼峰映射 configuration: map-underscore-to-camel-case: true #添加MP日志 打印执行的sql logging: level: com.jt.mapper: debug mapper文件 首先我们要写一个实体类pojo,注意这里的属性一定要和数据库的表列相对应 package com.jt.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; import java.io.Serializable; @Data @Accessors(chain = true) @TableName("user") //保证数据安全性和有效性必须序列化 public class User implements Serializable { @TableId(type = IdType.AUTO) //主键自增 private Integer id; private String name; private Integer num; } 下一步我们就要写dao层结构

我们因为使用的是mybatis-plus所以我们在这里写的代码比较少这也就是框架的好处

package com.jt.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.jt.pojo.User; /** * @author :王闫彭 * @date : 2023/5/28 */ public interface UseMapper extends BaseMapper { } service层结构

首先写service接口

package com.jt.service; import com.jt.pojo.User; import java.util.List; public interface UserService { List findAll(); void insertUser(User user); void updateUser(User user); void deleteUserById(Integer id); } service的实现类 package com.jt.service; import com.jt.mapper.UserMapper; import com.jt.pojo.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserServiceImpl implements UserService{ @Autowired private UserMapper userMapper; //mp的查询 @Override public List findAll() { return userMapper.selectList(null); } //MP的方式实现入库 @Override public void insertUser(User user) { userMapper.insert(user); } //mp的更新 @Override public void updateUser(User user) { userMapper.updateById(user); } //mp的删除 @Override public void deleteUserById(Integer id) { userMapper.deleteById(id); } } controller层结构 package com.jt.controller; import com.jt.pojo.User; import com.jt.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @Controller public class UserController { @Autowired private UserService userService; @GetMapping("/findUser") @ResponseBody public List findAjaxUser(){ return userService.findAll(); } @RequestMapping("/useraa/{id}/{name}/{num}") @ResponseBody public String insertUseraa(User user){ userService.insertUser(user); return "添加成功"; } @RequestMapping("/userbb/{id}/{name}") @ResponseBody public String updateUseraa(User user){ userService.updateUser(user); return "更新成功"; } @RequestMapping("/usercc/{id}") @ResponseBody public String deleteUsercc(@PathVariable Integer id){ userService.deleteUserById(id); //重新发起请求.. return "删除成功"; } }

启动类

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


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭