Spring boot+mybatis+thymeleaf 实现登录注册增删改查功能的示例代码

本文重在实现理解,过滤器,业务,逻辑需求,样式请无视。。

项目结构如下

1.idea新建Spring boot项目,在pom中加上thymeleaf和mybatis支持。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 http://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.1.3.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.jz</groupId>
 <artifactId>table</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>table</name>
 <description>Demo project for Spring Boot</description>

 <properties>
 <java.version>1.8</java.version>
 </properties>

 <dependencies>
 <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>

 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-thymeleaf</artifactId>
 </dependency>

 <dependency>
 <groupId>org.mybatis.spring.boot</groupId>
 <artifactId>mybatis-spring-boot-starter</artifactId>
 <version>1.3.1</version>
 </dependency>
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <scope>runtime</scope>
 </dependency>

 </dependencies>

 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 </plugins>
 </build>

</project>

2. 在项目resources目录下新建mybatis文件夹,用于存放mybatis配置文件。 在 application.properties 中配置本地数据源和mybatis配置文件地址, application.properties代码如下

spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=用户名
spring.datasource.password=密码
spring.jpa.showSql=true

mybatis:
mybatis.type-aliases-package=com.jz.table.entity
mybatis.mapper-locations=mybatis/*.xml

com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的,需要指定时区serverTimezone

2.2在启动类上加上扫描的Dao包

package com.jz.table;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.jz.table.dao")
public class TableApplication {

 public static void main(String[] args) {
 SpringApplication.run(TableApplication.class, args);
 }

}

3.数据库建两个表admin和userinfo用于登录和操作用

2019.10.3 现在mysql不能用admin作为表名了,请注意一下

4.开始写代码

entity:实体代码

1.Admin实体类

package com.jz.table.entity;

public class Admin {
 private Integer id;
 private String name;
 private Integer password;
 private String job;

 public Admin() {
 }

 public Admin(Integer id, String name, Integer password, String job) {
 this.id = id;
 this.name = name;
 this.password = password;
 this.job = job;
 }

 public Integer getId() {
 return id;
 }

 public void setId(Integer id) {
 this.id = id;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public Integer getPassword() {
 return password;
 }

 public void setPassword(Integer password) {
 this.password = password;
 }

 public String getJob() {
 return job;
 }

 public void setJob(String job) {
 this.job = job;
 }
}

2.UserInfo实体类

package com.jz.table.entity;

public class UserInfo {
 private Integer id;
 private String name;
 private Integer age;
 private String sex;
 public UserInfo() {
 }
 public UserInfo(Integer id, String name, Integer age, String sex) {
 this.id = id;
 this.name = name;
 this.age = age;
 this.sex = sex;
 }
 public Integer getId() {
 return id;
 }

 public void setId(Integer id) {
 this.id = id;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public Integer getAge() {
 return age;
 }

 public void setAge(Integer age) {
 this.age = age;
 }

 public String getSex() {
 return sex;
 }

 public void setSex(String sex) {
 this.sex = sex;
 }
}

Dao层代码
1.AdminDao

package com.jz.table.dao;

import com.jz.table.entity.Admin;

public interface AdminDao {
 //登录判断
 Admin login(Admin admin);
 //注册
 int addAdmin(Admin admin);
}

2.UserDao

package com.jz.table.dao;

import com.jz.table.entity.UserInfo;

import java.util.List;

public interface UserDao {
 //查
 List<UserInfo> findall();
 //增
 int adduser(UserInfo user);
 //根据Id查,用于修改时页面回显数据
 UserInfo findByid(Integer id);
 //修改
 int updateUser(UserInfo user);
 //删除
 int delUser(Integer id);
}

3.XML文件,因为没有业务逻辑,service省了,controller中直接引入dao
1.AdminMapper.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.jz.table.dao.AdminDao">
 <select id="login" parameterType="com.jz.table.entity.Admin" resultType="com.jz.table.entity.Admin">
 select name,job FROM admin WHERE name = #{name} AND password = #{password}
 </select>

 <insert id="addAdmin" parameterType="com.jz.table.entity.Admin">
 INSERT INTO admin (name,password,job) VALUES (#{name},#{password},#{job});
 </insert>
</mapper>

2.UserMapper.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.jz.table.dao.UserDao">
 <select id="findall" resultType="com.jz.table.entity.UserInfo">
 select * from userinfo
 </select>

 <insert id="adduser" parameterType="com.jz.table.entity.UserInfo">
 INSERT INTO userinfo(name,age,sex) VALUES (#{name},#{age},#{sex})
 </insert>

 <select id="findByid" parameterType="java.lang.Integer" resultType="com.jz.table.entity.UserInfo">
 SELECT * FROM userinfo where id = #{id}
 </select>

 <update id="updateUser" parameterType="com.jz.table.entity.UserInfo">
 update userinfo SET name=#{name },age =#{age},sex=#{sex} WHERE id = #{id}
 </update>

 <delete id="delUser" parameterType="java.lang.Integer">
 DELETE from userinfo WHERE id = #{id}
 </delete>
</mapper>

4.页面,在templates文件夹下新建public和user文件夹用来存放公共页面和user操作页面
public文件夹下新建成功、失败提示页
1.success.html

<!DOCTYPE html>
<!--引入thymeleaf-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>操作成功提示页</title>

</head>
<body>
<h1>操作成功</h1>

<a href="/index" rel="external nofollow" rel="external nofollow" > 返回首页</a>
</body>
</html>

2.false.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>操作失败提示页</title>
 <script th:src="@{/js/jquery-1.8.0.min.js}"></script>

</head>
<body>
<h1>操作失败,请检查数据重试</h1>
<input onclick="history.go(-1)" type="button" value="返回">

</body>
</html>

4.2在templates文件夹下新建login和register页面作为登录和注册页面
1.login.html

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>首页</title>

 <style>
 /*a标签去下划线和点击不变色,div内容居中*/
 a{
 text-decoration: none;
 color: #333333;
 }
 #idiv{text-align: center;border-radius: 20px;
 width: 300px;
 height: 350px;
 margin: auto;
 position: absolute;
 top: 0;
 left: 0;
 right: 0;
 bottom: 0;}
 </style>
</head>
<body>
<div id="idiv">
 <form action="/gologin" method="post">
 请输入姓名<input id="name" name="name" required="required"><br><br>
 请输入密码<input id="password" name="password" type="password" placeholder="仅支持正整数" required="required"><br><br>
 <input type="submit" value="登录"> <button> <a href="/goregister" rel="external nofollow" >注册</a></button>
 </form>
</div>
</body>
</html>

2.register.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>账号注册</title>
 <script th:src="@{/js/jquery-1.8.0.min.js}"></script>
</head>
<body>
<h2>账号注册</h2>
请输入姓名:<input type="text" id="name"/><br><br>
请输入密码:<input type="password" id="password" placeholder="仅支持整数" /><br><br>
请确认密码:<input type="password" id="passwordTwo" placeholder="仅支持整数"/><br><br>
请选择角色:<select id="job" style="width: 173px">
 <option value="管理员">管理员</option>
 </select><br><br>
<button onclick="register()">注册</button>
</body>
<script>
 function register() {
 var name = $("#name").val();
 var password1 = $("#password").val();
 var password2 = $("#passwordTwo").val();
 var job = $("#job").val();
 if (Number(password1) == Number(password2)){
 $.post("/register",{name:name,password:password1,job:job},function (res) {
 if (res ==true){
  alert("注册成功");
  window.location.href ="/login";
 } else {
  alert("注册失败,请检查数据重试");
 }
 })
 }else {
 alert("两次密码不一致!");
 }
 }
</script>
</html>

3.controller中代码

@Controller
public class TestController {
 @Resource
 private AdminDao ad;
 @Resource
 private UserDao ud;

 @RequestMapping("/login")//主页
 public String index(){
 return "login";
 }

 @RequestMapping("/goregister")//去注册页面
 public String goregister(){
 return "register";
 }
 @RequestMapping("/register")//注册
 @ResponseBody
 public boolean register(Admin admin){
 int i = ad.addAdmin(admin);
 if (i>0){
 return true;
 }else {
 return false;
 }
 }

 @RequestMapping("/gologin")//登录获取用户信息存到seccion
 public String gologin(Admin admin,HttpServletRequest request,Model model){
 Admin aa = ad.login(admin);
 if (aa==null){
 return "public/false";
 }
 HttpSession session = request.getSession();
 session.setAttribute("aname",admin.getName());
 session.setAttribute("apassword",admin.getPassword());
 List<UserInfo> userlist = ud.findall();
 model.addAttribute("admin",aa);
 model.addAttribute("alist",userlist);
 return "user/index";
 }

 @RequestMapping("/index")//从其他页面操作后返回列表页面(重复登录)
 public String login(Admin admin,Model model,HttpServletRequest request){
 HttpSession session = request.getSession();
 admin.setName((String) session.getAttribute("aname"));
 admin.setPassword((Integer) session.getAttribute("apassword"));
 Admin aa = ad.login(admin);
 List<UserInfo> userlist = ud.findall();
 model.addAttribute("admin",aa);
 model.addAttribute("alist",userlist);
 return "user/index";
 }
}

4.3user文件夹下新建index,addUser,updateUser页面,作为主页,添加,修改页面

1.index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>首页</title>
 <style>a{text-decoration:none}</style>
 <script th:src="@{/js/jquery-1.8.0.min.js}"></script>
</head>
<body>
欢迎你 :<input th:value="${admin.name}" style="border: none; outline: none"/><br><br><br><br>
<h2>人员信息维护</h2>
<table width="888" border="1">
 <thead>
 <tr>
 <th>id</th>
 <th>姓名</th>
 <th>年龄</th>
 <th>性别</th>
 <th>操作</th>
 </tr>
 <tr th:each="user:${alist}">
 <td align="center" th:text="${user.id}"></td>
 <td align="center" th:text="${user.name}"></td>
 <td align="center" th:text="${user.age}"></td>
 <td align="center" th:text="${user.sex}"></td>
 <td align="center"><a th:href="@{'/goupdate/'+${user.id}}" rel="external nofollow" >修改</a>
  <a th:href="@{'/godel/'+${user.id}}" rel="external nofollow" >删除</a>
 </td>
 </tr>
 </thead>
</table>
<button><a href="/goadd" rel="external nofollow" >添加</a></button>
</body>
</html>

2.addUser.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>添加用户</title>
 <script th:src="@{/js/jquery-1.8.0.min.js}"></script>
</head>
<body>
<h2>我是添加页面</h2>

请输入姓名:<input id="name" name="name" type="text" /><br><br>
请输入年龄:<input id="age" name="age" type="text" /><br><br>
请选择性别:<select id="sex" name="sex" style="width: 173px">
 <option value="男">男</option>
 <option value="女">女</option>
 </select><br><br>
<button onclick="goadd()" name="sub" id="sub">添加</button>
<button name="button" onclick="javascript:history.back(-1);">返回</button>
</body>
<script>
 function goadd() {
 var name = $("#name").val();
 var age = $("#age").val();
 var sex = $("#sex").val();
 $.post("/addUser",{name:name,age:age,sex:sex},function (res) {
 if (res==true){
 alert("添加成功")
 window.location.href ="/index";
 }else {
 alert("添加失败,请检查数据重试!");
 }
 })
 }
</script>
</html>

3.updateUser.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="UTF-8">
 <title>修改用户</title>
 <script th:src="@{/js/jquery-1.8.0.min.js}"></script>
</head>
<body>
<h2>这是修改页面</h2>
<input type="hidden" id="id" th:value="${user.id}"><br><br>
请输入姓名:<input id="name" th:value="${user.name}"/><br><br>
请输入年龄:<input id="age" th:value="${user.age}"/><br><br>
请选择性别:<select id="sex" style="width: 173px">
 <option value="男">男</option>
 <option value="女">女</option>
 </select><br><br>
<button onclick="goupdate()">修改</button>
<button name="button" onclick="javascript:history.back(-1);">返回</button>
</body>
<script>
 function goupdate() {
 var id=$("#id").val();
 var name = $("#name").val();
 var age = $("#age").val();
 var sex = $("#sex").val();
 $.post("/update",{id:id,name:name,age:age,sex:sex},function (res) {
 if (res==true) {
 alert("修改成功");
 window.location.href="/index" rel="external nofollow" rel="external nofollow" ;
 }else {
 alert("修改失败,请检查数据重试!");
 }
 })
 }
</script>
</html>

4.controller中代码

@RequestMapping("/goadd")//去添加页面
public String goadd(){
 return "user/addUser";
}
@RequestMapping("/addUser")//添加信息
@ResponseBody
public boolean addUser(UserInfo user){
 int i = ud.adduser(user);
 if (i>0){
 return true;
 }else {
 return false;
 }
}
@RequestMapping("/goupdate/{id}")//去修改页面,回显数据
public String goupdate(@PathVariable("id") int id,Model model){
 UserInfo user = ud.findByid(id);
 model.addAttribute("user",user);
 return "user/updateUser";
}
@RequestMapping("/update")//修改
@ResponseBody
public boolean updateUser(UserInfo user){
 int i = ud.updateUser(user);
 if (i>0){
 return true;
 }else {
 return false;
 }
}
@RequestMapping("/godel/{id}")//删除
public String delUser(@PathVariable("id") Integer id){
 ud.delUser(id);
 return "public/success";
}

5.完整controller代码

package com.jz.table.controller;
import com.jz.table.dao.AdminDao;
import com.jz.table.dao.UserDao;
import com.jz.table.entity.Admin;
import com.jz.table.entity.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class TestController {
 @Resource
 private AdminDao ad;
 @Resource
 private UserDao ud;

 @RequestMapping("/login")//主页
 public String index(){
 return "login";
 }

 @RequestMapping("/goregister")//去注册页面
 public String goregister(){
 return "register";
 }
 @RequestMapping("/register")//注册
 @ResponseBody
 public boolean register(Admin admin){
 int i = ad.addAdmin(admin);
 if (i>0){
 return true;
 }else {
 return false;
 }
 }

 @RequestMapping("/gologin")//登录获取用户信息存到seccion
 public String gologin(Admin admin,HttpServletRequest request,Model model){
 Admin aa = ad.login(admin);
 if (aa==null){
 return "public/false";
 }
 HttpSession session = request.getSession();
 session.setAttribute("aname",admin.getName());
 session.setAttribute("apassword",admin.getPassword());
 List<UserInfo> userlist = ud.findall();
 model.addAttribute("admin",aa);
 model.addAttribute("alist",userlist);
 return "user/index";
 }

 @RequestMapping("/index")//从其他页面操作后返回列表页面(重复登录)
 public String login(Admin admin,Model model,HttpServletRequest request){
 HttpSession session = request.getSession();
 admin.setName((String) session.getAttribute("aname"));
 admin.setPassword((Integer) session.getAttribute("apassword"));
 Admin aa = ad.login(admin);
 List<UserInfo> userlist = ud.findall();
 model.addAttribute("admin",aa);
 model.addAttribute("alist",userlist);
 return "user/index";
 }

 @RequestMapping("/goadd")//去添加页面
 public String goadd(){
 return "user/addUser";
 }
 @RequestMapping("/addUser")//添加信息
 @ResponseBody
 public boolean addUser(UserInfo user){
 int i = ud.adduser(user);
 if (i>0){
 return true;
 }else {
 return false;
 }
 }
 @RequestMapping("/goupdate/{id}")//去修改页面,回显数据
 public String goupdate(@PathVariable("id") int id,Model model){
 UserInfo user = ud.findByid(id);
 model.addAttribute("user",user);
 return "user/updateUser";
 }
 @RequestMapping("/update")//修改
 @ResponseBody
 public boolean updateUser(UserInfo user){
 int i = ud.updateUser(user);
 if (i>0){
 return true;
 }else {
 return false;
 }
 }
 @RequestMapping("/godel/{id}")//删除
 public String delUser(@PathVariable("id") Integer id){
 ud.delUser(id);
 return "public/success";
 }

}

效果如图

到此这篇关于Spring boot+mybatis+thymeleaf 实现登录注册增删改查功能的示例代码的文章就介绍到这了,更多相关Spring boot mybatis thymeleaf 登录注册增删改查内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • springboot用thymeleaf模板的paginate分页完整代码

    本文根据一个简单的user表为例,展示 springboot集成mybatis,再到前端分页完整代码(新手自学,不足之处欢迎纠正): 先看java部分 pom.xml 加入 <!--支持 Web 应用开发,包含 Tomcat 和 spring-mvc. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web&l

  • 在WINXP下建立VPN服务器的方法

    最近想在WinXP上创建一个VPN服务器,在网上找了找,找到了相关资料,转来贴之. 利用WINXP不需要第三方软件,可以直接构建一个VPN服务器,如果没有采用SOFTETHER,虚拟HUB的必要的话,要实现VPN,可以直接用WINXP来实现.     接下来,我们以WINXP操作系统,宽带连接来构建一个虚拟专用网络. 第一步: VPN服务器的建立 右单击,网上邻居,选属性,打开网络连接属性. 在"网络任务"里选择,创建一个新的连接. 打开新建连接向导. 然后,点 下一步. 在 &quo

  • SpringBoot+mybatis+thymeleaf实现登录功能示例

    1.项目文件目录一栏 2.开始工作 先按照上图建立好相应的controller,mapper等文件. 接着进行一个配置 首先是application.properties server.port=8080#启动端口 #加载Mybatis配置文件 mybatis.mapper-locations = classpath:mapper/*.xml #数据源必填项 spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver spring.

  • springboot如何使用thymeleaf模板访问html页面

    引言 在传统的web开发中通常使用jsp页面,首先需要在pom文件中引入springmvc相关的包,然后写springmvc的配置文件(包括访问资源的路径解析),之后还需再web.xml中配置访问路由.这无疑太麻烦了,每次开发前都需要编写大量的配置文件. springboot为此提供了高效便捷的解决方案,只需再pom.xml中添加web开发的依赖,便可进行web开发,省去了繁琐的配置步骤. 下面为web开发引入的依赖 <dependency> <groupId>org.spring

  • 详解SpringBoot+Thymeleaf 基于HTML5的现代模板引擎

    序言: Thymeleaf 是Java服务端的模板引擎,与传统的JSP不同,前者可以使用浏览器直接打开,因为可以忽略掉拓展属性,相当于打开原生页面,给前端人员也带来一定的便利.如果你已经厌倦了JSP+JSTL的组合,Thymeleaf或许是个不错的选择!本工程传送门:SpringBoot-Web-Thymeleaf 开始使用 1.引入依赖 SpringBoot默认提供了Thymeleaf的Starter,只需简单引入依赖即可. <dependency> <groupId>org.s

  • springboot+thymeleaf+druid+mybatis 多模块实现用户登录功能

    项目代码:https://github.com/bruceq/supermarket 项目结构: 依赖关系: common:公共层,无依赖 dao:数据层,依赖common service:服务层,依赖dao.common web:应用层,依赖dao.common.service 注:启动类在web层中 父依赖pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:/

  • VPN技术详解

    一.引言     虚拟专用网络可以实现不同网络的组件和资源之间的相互连接.虚拟专用网络能够利用Internet或其它公共互联网络的基础设施为用户创建隧道,并提供与专用网络一样的安全和功能保障. 740)this.width=740" border=undefined> (图1) 虚拟专用网络允许远程通讯方,销售人员或企业分支机构使用Internet等公共互联网络的路由基础设施以安全的方式与位于企业局域网端的企业服务器建立连接.虚拟专用网络对用户端透明,用户好象使用一条专用线路在客户计算机和

  • Spring boot+mybatis+thymeleaf 实现登录注册增删改查功能的示例代码

    本文重在实现理解,过滤器,业务,逻辑需求,样式请无视.. 项目结构如下 1.idea新建Spring boot项目,在pom中加上thymeleaf和mybatis支持.pom.xml代码如下 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3

  • Mybatis实现动态增删改查功能的示例代码

    一.Mybatis 流程简介 最近在看 Mybatis 的源码,大致了解整个框架流程后便手写了一个特别简单的SimpMybatis的小Demo,来巩固这整个框架的学习.下图是我所画的框架大致执行流程:

  • Mybatis Plus使用条件构造器增删改查功能的实现方法

    java后端层级结构 Controller 接口层 接口层比较好理解,它是面向web网络的接口,使用http格式去调用 /** * 图文课程管理Controller */ @RestController @RequestMapping("/driver/imageCourse") public class TImageCourseController extends BaseController { @Autowired private ITImageCourseService tIm

  • koa+mongoose实现简单增删改查接口的示例代码

    配合上一篇文章的联系人应用(https://www.jb51.net/article/161160.htm),实现配套的基于nodejs的后台增删改查接口 1. 所需工具 node.js mongoDB 2. 主要node模块 koa(https://koa.bootcss.com,一个nodejs的开发框架),mongoose(https://mongoosejs.com,mongDB操作工具) 3. 目录结构 4. 启动MongoDB 首先在MongoDB安装盘的根目录下(这里假设是D盘)新

  • C#对Access进行增删改查的完整示例

    这篇文章整理了C#对Access数据库的查询.添加记录.删除记录和更新数据等一系列的操作示例,有需要的可以参考学习. 首先是AccessHelper.cs,网上有下载,下面附送一份: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.OleDb; using System.Data

  • MyBatis后端对数据库进行增删改查等操作实例

    目录 1.MyBatis 是什么? 2. MyBatis 的重要性 3. MyBatis 查询 3.1 创建数据库和表 3.2 添加MyBatis框架⽀持 3.2.1 新项目添加MyBatis 3.2.1 老项⽬添加 MyBatis 3.3 配置连接字符串和MyBatis 3.3.1 配置连接字符串 3.3.2 配置mybatis 中的 xml 保存路径 3.4 添加后端代码 3.4.1 添加实体类 3.4.2 添加 mapper 接口 3.4.3 添加UserMapper.xml 3.4.4

  • Mybatis开发环境搭建实现数据的增删改查功能

    config.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 拿到数据库

  • SpringBoot整合Mybatis与thymleft实现增删改查功能详解

    首先我们先创建项目 注意:创建SpringBoot项目时一定要联网不然会报错 项目创建好后我们首先对 application.yml 进行编译 #指定端口号server: port: 8888#配置mysql数据源spring:  datasource:    driver-class-name: com.mysql.cj.jdbc.Driver    url: jdbc:mysql://localhost:3306/nba?serverTimezone=Asia/Shanghai    use

  • Mybatis基于xml配置实现单表的增删改查功能

    Mybatis入门-基于配置实现单表的增删改查 Mybatis简介 官网链接:https://mybatis.org/mybatis-3/zh/index.html.更加详细的信息可以去官网查看. MyBatis 是一款优秀的持久层框架,它支持自定义 SQL.存储过程以及高级映射.MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作.MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型.接口和 Java POJO(Plain Old Java Object

  • 使用Spring Data R2DBC +Postgres实现增删改查功能

    在本教程中,我想向您展示如何通过带有Spring WebFlux的Spring Data R2DBC 执行各种Postgres CRUD操作. R2DBC代表反应式关系数据库连接. 像JPA(Java持久性API)一样,R2DBC是关系数据库的反应性驱动程序的规范.由于它是一个单独的规范,因此请勿与JPA / Hibernate功能(如@OneToMany,@ManyToMany 等)比较. 我们将开发一个名为product-service的Spring Boot应用程序,该应用程序负责创建新产

随机推荐