您现在的位置是:主页 > news > 在线视频网站怎么做/百度2022新版下载

在线视频网站怎么做/百度2022新版下载

admin2025/5/4 16:17:22news

简介在线视频网站怎么做,百度2022新版下载,自己做的网站页面错误,做外汇哪个网站看外国消息SSM(SpringSpring MVC MyBatis)是当前主流的框架组合开发方式之一,普遍被应用于互联网项目之中。下面以一个用户查询案例为例,讲解如何在Spring Boot中使用MyBatis。 1、准备数据库环境 在MySQL数据库中中,创建一个名…

在线视频网站怎么做,百度2022新版下载,自己做的网站页面错误,做外汇哪个网站看外国消息SSM(SpringSpring MVC MyBatis)是当前主流的框架组合开发方式之一,普遍被应用于互联网项目之中。下面以一个用户查询案例为例,讲解如何在Spring Boot中使用MyBatis。 1、准备数据库环境 在MySQL数据库中中,创建一个名…

SSM(Spring+Spring MVC +MyBatis)是当前主流的框架组合开发方式之一,普遍被应用于互联网项目之中。下面以一个用户查询案例为例,讲解如何在Spring Boot中使用MyBatis。

1、准备数据库环境
在MySQL数据库中中,创建一个名为microservice的数据库,在microservice中创建数据表tb_user,并在表中插入3条数据。
在这里插入图片描述
2、创建项目,添加依赖
创建一个依赖于Web模块的Spring boot 项目,在项目的pom.xml中添加如下依赖配置信息。
在这里插入图片描述
在上述配置代码中,mybatis-spring-boot-starter是Spring boot中的MyBatis启动器配置,添加依赖后,Spring Boot会将MyBatis所需的JAR包自动添加到项目中。MySQL的驱动信息配置主要用于添加mysql数据库驱动JAR包,此JAR包会自动依照Spring Boot中的版本加载相应版本,也可以通过之低昂版本。
3、编写配置文件
在application。properties中添加数据库配置信息及日志信息。
在这里插入图片描述
4、创建实体类
在项目的src/main/java中创建包com.learn.spring.po,并在该包中创建实体类User。
在这里插入图片描述
5、编写Mapper
在项目的src/main/java中创建包com.learn.spring.mapper,并在该包中创建接口文件UserMapper。
在这里插入图片描述
在上述代码中,@Mapper是MyBatis框架用于声明Mapper接口的注解,@Select是用于映射查询SQL语句的注解,@Delete是用于映射删除SQL语句的注解。
6、编写Service
①编写接口。在项目的src/main/java中创建包com.learn.spring.service,并在该包中创建接口文件UserService。
在这里插入图片描述
②编写实现类。在项目的src/main/java中创建包com.learn.spring.service.impl,并在该包中创建接口文件UserServiceImpl。
在这里插入图片描述
7、编写Controller
在项目的src/main/java中创建包com.learn.spring.controller,并在该包中创建用户控制器类UserController。
在这里插入图片描述
8、实现前端页面
将Easy UI框架的资源文件拷贝到src/main/resource下的static文件夹中,并在static文件夹中创建页面文件user.html。
在这里插入图片描述
9、启动项目,查看结果
启动项目,在浏览器地址栏中输入访问地址http://localhost:8080/user.html。
在这里插入图片描述

☛多学一招:使用YAML配置外部属性

  • YAML是JSON的一个超集,可以非常方便的将外部配置以层次结构形式存储起来,当项目的类路径中有SnakeYAML库(spring-boot-starter中已经被包含)时,SpringApplication类将自动支持YAML作为properties的替代。
  • 如果将项目中的application.properties文件修改为YAML文件(后缀为.yml或yaml)则配置信息如下:
    在这里插入图片描述
    从上述配置文件可以看出,yml文件是一个树状结构的配置,它与properties文件相比,有很大不同,需注意如下几点:
    (1)在properties文件中是以"."进行分割的,在yml中使用“:”进行分割的。
    (2)yml的数据格式和json的格式很像,都是K-v格式,并且通过“:”进行赋值。
    (3)每个k的冒号后面一定都要加一个空格,例如driver-class-name后面的“:”之后,需要有一个空格,否则文件会报错。
    源码文本:
    文件系统结构:
    在这里插入图片描述
    pom.xml
<!-- MyBatis启动器 --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.1.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency>

application.propertites

在这里插入代码片

User.java

package com.itheima.springboot.po;import java.io.Serializable;public class User implements Serializable{/*** */private static final long serialVersionUID = 1664137510764351595L;private Integer id;private String username;private String address;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public User() {super();}public User(Integer id, String username, String address) {super();this.id = id;this.username = username;this.address = address;}
}

UserMapper.java

package com.itheima.springboot.mapper;import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.itheima.springboot.po.User;
@Mapper
public interface UserMapper {//查询所有用户@Select("select * from tb_user")List<User> getAllUsers();//删除用户@Delete("Delete FROM tb_user WHERE id =#{id}")void delete(Integer id);}

UserService.java

package com.itheima.springboot.service;import java.util.List;
import com.itheima.springboot.po.User;public interface UserService
{//查询所有List<User> getAllUsers();//删除数据void deleteUser(Integer id);
}

UserServiceImpl.java

package com.itheima.springboot.service.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import com.itheima.springboot.mapper.UserMapper;
import com.itheima.springboot.po.User;
import com.itheima.springboot.service.UserService;
@Service
@Transactional
public class UserServiceImpl implements UserService{//注入用户Mapper@Autowiredprivate UserMapper userMapper;//查询所有用户@Override@Cacheable(value="UserCache",key="'user.getAllUsers'")public List<User> getAllUsers(){return this.userMapper.getAllUsers();}//删除用户@Override@CacheEvict(value="UserCache",key="'user.getAllUsers'")public void deleteUser(Integer id) {System.out.println("删除了id为"+id+"的用户");this.userMapper.delete(id);}
}

UserController.java

package com.itheima.springboot.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import com.itheima.springboot.po.User;
import com.itheima.springboot.service.UserService;
@RestController
@RequestMapping("/user")
public class UserController {@Autowiredprivate UserService userService;@RequestMapping("/userList")public List<User> getAllUsers(){List<User> list = this.userService.getAllUsers();return list;}@RequestMapping("/delete/{id}")public void delete(@PathVariable Integer id){this.userService.deleteUser(id);}
}

user.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户信息</title>
<link rel="stylesheet" type="text/css" href="ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="ui/themes/icon.css">
<script type="text/javascript" src="ui/jquery.min.js"></script>
<script type="text/javascript" src="ui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="ui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">$(function(){		$('#grid').datagrid({url:'user/userList',fit:true,columns:[[{field:'id',title:'编号',width:50},    {field:'username',title:'姓名',width:200},    {field:'address',title:'地址',width:200}]]		});		});
</script>
</head>
<body>
<table id="grid"></table>
</body>
</html>

application.yml

#DB Configuration
spring:datasource:driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/microserviceusername: root password: root
#logging
logging:level: com.itheima.springboot: debug