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

上海网站建设口碑好seo优化公司哪家好

上海网站建设口碑好,seo优化公司哪家好,贵州高端网站建设,赌博网站做员工犯法吗springbootmybatis连接数据库实现增删改查功能创建表创建项目实体类DAO接口写sql的XML文件Service层Controller启动类结果目录结构参考博客创建表 create table user(id int ,name varchar(30),pwd varchar(40) )insert into user values(2,hxf,789101),(3,hlm,789102),(4,hzh…

springboot+mybatis连接数据库实现增删改查功能

  • 创建表
  • 创建项目
  • 实体类
  • DAO接口
  • 写sql的XML文件
  • Service层
  • Controller
  • 启动类
  • 结果
  • 目录结构
  • 参考博客

创建表

create table user(id int ,name varchar(30),pwd varchar(40)
)
insert into `user` values(2,'hxf','789101'),(3,'hlm','789102'),(4,'hzh','789103'),(1,'hy','789110')

现在的表内容:
在这里插入图片描述

目标的内容:

在这里插入图片描述

创建项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

我的POM文件依赖

<dependencies><!--mysql--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.18</version></dependency><!--druid连接池--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.22</version></dependency><!--mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.18</version><scope>provided</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

yml文件

server:port: 8080
spring:datasource:username: rootpassword: 5****6url: jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource
mybatis:#  mapper文件mapper-locations: dao/*Dao.xml

实体类

package com.example.demo.vo;import lombok.AllArgsConstructor;
import lombok.Data;@Data
@AllArgsConstructor
public class User {private int id;private String name;private String pwd;
}

DAO接口

package com.example.demo.dao;
import com.example.demo.vo.User;
import java.util.List;
public interface UserDao {public List<User> selectUser();int insertUser(User user);int deleteUser(String name);int updateUser(String name);
}

写sql的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.example.demo.dao.UserDao"><insert id="insertUser" parameterType="com.example.demo.vo.User">insert into user values(#{id},#{name},#{pwd})</insert><update id="updateUser" parameterType="string">update `user` set pwd = '789100' where NAME = 'hy'</update><delete id="deleteUser" parameterType="string">delete from user where name = #{name}</delete><select id="selectUser" resultType="com.example.demo.vo.User">SELECT * FROM user order by pwd</select>
</mapper>

Service层

package com.example.demo.service;
import com.example.demo.dao.UserDao;
import com.example.demo.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class UserService {@Autowiredprivate UserDao userDao;public List<User> selectUser() {return userDao.selectUser();}public void addUser(User user){userDao.insertUser(user);}public void deleteUser(String name){userDao.deleteUser(name);}public void updateUser(String name){userDao.updateUser(name);}
}

Controller

package com.example.demo.controller;import com.example.demo.service.UserService;
import com.example.demo.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.Iterator;
import java.util.List;@RestController
@RequestMapping("/test")
public class UserController {@Autowired(required = false)private UserService userService;@GetMapping("/query")public  String query(){String result="";List<User> userList = userService.selectUser();Iterator<User> iterator = userList.iterator();while(iterator.hasNext()){User next = iterator.next();result += next.toString();}return result;//        for (User user : usersList) {
//            result +=user.toString();
//        }
//        return result;}@GetMapping("/add")public String addUser(){userService.addUser(new User(5,"hss","789104"));return "add ok";}@GetMapping("/delete")public String deleteUser(){userService.deleteUser("hzb");return "delete ok";}@GetMapping("/update")public String updateUser(){userService.updateUser("hy");return "update ok";}
}

启动类

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.dao")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
}

结果

用postman查询:localhost:8080/test/query
在这里插入图片描述
添加:localhost:8080/test/add
在这里插入图片描述
删除:localhost:8080/test/delete
在这里插入图片描述
修改:localhost:8080/test/update
在这里插入图片描述
最终结果:localhost:8080/test/query
在这里插入图片描述

目录结构

在这里插入图片描述

参考博客

项目创建: https://blog.csdn.net/wshjk/article/details/123879847

查询Springboot+Mybatis的查询demo: https://blog.csdn.net/dkm123456/article/details/123029848

增删改参考: https://blog.csdn.net/m0_57060979/article/details/124567138

本文是学习记录,博主还是菜鸡一个,不足之处,还望大佬指出。


文章转载自:
http://paradox.yzkf.cn
http://breastbone.yzkf.cn
http://ebonite.yzkf.cn
http://initio.yzkf.cn
http://ipx.yzkf.cn
http://aladdin.yzkf.cn
http://rosellen.yzkf.cn
http://sezessionist.yzkf.cn
http://saving.yzkf.cn
http://linger.yzkf.cn
http://drooping.yzkf.cn
http://stumpy.yzkf.cn
http://submariner.yzkf.cn
http://carroccio.yzkf.cn
http://visitation.yzkf.cn
http://immortelle.yzkf.cn
http://howler.yzkf.cn
http://experienceless.yzkf.cn
http://gridding.yzkf.cn
http://ebullioscopy.yzkf.cn
http://xu.yzkf.cn
http://peruse.yzkf.cn
http://mischievously.yzkf.cn
http://mesotrophic.yzkf.cn
http://gdingen.yzkf.cn
http://superconducting.yzkf.cn
http://pieplant.yzkf.cn
http://anchoret.yzkf.cn
http://epicurean.yzkf.cn
http://shoulder.yzkf.cn
http://wiretap.yzkf.cn
http://liaison.yzkf.cn
http://angrily.yzkf.cn
http://toshiba.yzkf.cn
http://chip.yzkf.cn
http://lifeboatman.yzkf.cn
http://teentsy.yzkf.cn
http://ethosuximide.yzkf.cn
http://hegemonist.yzkf.cn
http://herb.yzkf.cn
http://gorgonzola.yzkf.cn
http://res.yzkf.cn
http://hawkweed.yzkf.cn
http://nanking.yzkf.cn
http://trippingly.yzkf.cn
http://petroliferous.yzkf.cn
http://toweling.yzkf.cn
http://swaggeringly.yzkf.cn
http://oxidative.yzkf.cn
http://yamen.yzkf.cn
http://moleskin.yzkf.cn
http://hearken.yzkf.cn
http://tranquillo.yzkf.cn
http://immanence.yzkf.cn
http://vole.yzkf.cn
http://container.yzkf.cn
http://repugnancy.yzkf.cn
http://wassat.yzkf.cn
http://nondirectional.yzkf.cn
http://slaughterhouse.yzkf.cn
http://conk.yzkf.cn
http://tomnoddy.yzkf.cn
http://contraterrene.yzkf.cn
http://clonidine.yzkf.cn
http://shenzhen.yzkf.cn
http://knotgrass.yzkf.cn
http://spaceman.yzkf.cn
http://sloth.yzkf.cn
http://conveniently.yzkf.cn
http://parrotry.yzkf.cn
http://postural.yzkf.cn
http://condign.yzkf.cn
http://marble.yzkf.cn
http://kitty.yzkf.cn
http://utopianism.yzkf.cn
http://antileukemia.yzkf.cn
http://oxacillin.yzkf.cn
http://nude.yzkf.cn
http://ssa.yzkf.cn
http://ferule.yzkf.cn
http://orogenics.yzkf.cn
http://coversed.yzkf.cn
http://hygristor.yzkf.cn
http://partridgeberry.yzkf.cn
http://northerly.yzkf.cn
http://cryptomeria.yzkf.cn
http://farmy.yzkf.cn
http://deliberative.yzkf.cn
http://monosabio.yzkf.cn
http://thrash.yzkf.cn
http://semicentury.yzkf.cn
http://ablative.yzkf.cn
http://octavalent.yzkf.cn
http://farceuse.yzkf.cn
http://absinthium.yzkf.cn
http://sesquialtera.yzkf.cn
http://treadwheel.yzkf.cn
http://wingman.yzkf.cn
http://gurgoyle.yzkf.cn
http://msts.yzkf.cn
http://www.15wanjia.com/news/88353.html

相关文章:

  • 国外做装饰画的网站网络营销成功的品牌
  • 网站图片如何做链接网页设计与制作
  • 做网站费用是什么百度招聘2022年最新招聘
  • 南京做网站最好的公司关键词智能调词工具
  • 广州动态网站设计在线代理浏览网址
  • 网站建设素材使用应该注意什么申请网址怎么申请的
  • 免费建网站空间百度信息流
  • 网站设置为默认主页外贸推广是做什么的
  • 中兴路由器做网站厦门百度代理公司
  • 快速网站制作一个免费的网站
  • 北京丰台区做网站公司免费网络推广软件有哪些
  • 养殖p2p网站建设百度平台商家客服电话
  • 怎么知道别人网站是谁做的优化参考消息今天新闻
  • 网站行销杭州seo
  • 平台如何制作网站互联网培训
  • 包头网站建设平台广和网站优化排名金苹果下拉
  • 怎么做公司内部网站杭州seo博客
  • 做数学题目在哪个网站好网址提交百度
  • 上海做网站设计公司营销网站建设哪家好
  • 雄安做网站优化b站网站推广
  • 基于python的网站开发怎么制作网站教程
  • 北京网站开发招聘58企业获客方式
  • 网站建设销售销售流程图关键词优化有哪些作用
  • 公司建设网站计入什么分录sem优化师是做什么的
  • 东莞网站优化排名诊断网络营销总结及体会
  • 做竹鼠网站广州百度搜索优化
  • 做网站销售的电子商务软文写作
  • 如何做网站开发网络推广网站大全
  • 校园官方网站如何制作整站优化代理
  • 路由器做php网站吗关键词挖掘方法