5/26 16:54

This commit is contained in:
zyx 2023-05-26 16:54:21 +08:00
parent a0b9985df0
commit 51cc05eb27
32 changed files with 601 additions and 21 deletions

6
.idea/compiler.xml generated
View File

@ -12,9 +12,10 @@
<module name="springmvc-01-523" /> <module name="springmvc-01-523" />
<module name="demo516" /> <module name="demo516" />
<module name="demo515" /> <module name="demo515" />
<module name="springboot525-526" />
<module name="spring-mybatis01-522-523" /> <module name="spring-mybatis01-522-523" />
<module name="springboot525" />
<module name="springboot-524" /> <module name="springboot-524" />
<module name="springboot-mbp-526" />
<module name="mybatis519" /> <module name="mybatis519" />
<module name="springmvc-02-524" /> <module name="springmvc-02-524" />
<module name="spring522-annotation" /> <module name="spring522-annotation" />
@ -27,7 +28,8 @@
<component name="JavacSettings"> <component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE"> <option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="springboot-524" options="-parameters" /> <module name="springboot-524" options="-parameters" />
<module name="springboot525" options="-parameters" /> <module name="springboot-mbp-526" options="-parameters" />
<module name="springboot525-526" options="-parameters" />
</option> </option>
</component> </component>
</project> </project>

5
.idea/encodings.xml generated
View File

@ -23,8 +23,9 @@
<file url="file://$PROJECT_DIR$/spring522/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/spring522/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot-524/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot-524/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot-524/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot-524/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot525/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot-mbp-526/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot525/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot525-526/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot525-526/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-02-524/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-02-524/src/main/java" charset="UTF-8" />

2
.idea/misc.xml generated
View File

@ -25,6 +25,8 @@
<option value="$PROJECT_DIR$/springmvc-02-524/pom.xml" /> <option value="$PROJECT_DIR$/springmvc-02-524/pom.xml" />
<option value="$PROJECT_DIR$/springboot-524/pom.xml" /> <option value="$PROJECT_DIR$/springboot-524/pom.xml" />
<option value="$PROJECT_DIR$/springboot525/pom.xml" /> <option value="$PROJECT_DIR$/springboot525/pom.xml" />
<option value="$PROJECT_DIR$/springboot525-526/pom.xml" />
<option value="$PROJECT_DIR$/springboot-mbp-526/pom.xml" />
</list> </list>
</option> </option>
</component> </component>

View File

@ -0,0 +1,73 @@
<?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.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot-mbp-526</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-mbp-526</name>
<description>springboot-mbp-526</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package cn.czyx007;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,100 @@
package cn.czyx007.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author zyx
* @since 2023-05-26
*/
@TableName("tb_brand")
public class Brand implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String brandName;
private String companyName;
private Integer ordered;
private String description;
private Integer status;
private LocalDateTime createDate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public Integer getOrdered() {
return ordered;
}
public void setOrdered(Integer ordered) {
this.ordered = ordered;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public LocalDateTime getCreateDate() {
return createDate;
}
public void setCreateDate(LocalDateTime createDate) {
this.createDate = createDate;
}
@Override
public String toString() {
return "Brand{" +
"id=" + id +
", brandName=" + brandName +
", companyName=" + companyName +
", ordered=" + ordered +
", description=" + description +
", status=" + status +
", createDate=" + createDate +
"}";
}
}

View File

@ -0,0 +1,48 @@
package cn.czyx007.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* (User)实体类
*
* @author 张宇轩
* @since 2023-05-25 15:30:24
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("user")
public class User implements Serializable {
private static final long serialVersionUID = 872728960100083467L;
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 姓名
*/
//exist=true表示是数据库表中的字段默认为true
@TableField(value = "name", exist = true)
private String name;
/**
* 年龄
*/
private Integer age;
/**
* 邮箱
*/
private String email;
//不是数据库表的字段
@TableField(exist = false)
private String deptName;
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.config;
import cn.czyx007.interceptor.MyInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author : 张宇轩
* @createTime : 2023/5/26 - 16:13
*/
//配置类配置拦截器redis解决CORS跨域问题
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
}
}

View File

@ -0,0 +1,21 @@
package cn.czyx007.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author : 张宇轩
* @createTime : 2023/5/26 - 14:25
*/
@Configuration
public class MybatisPlusConfig {
//@Bean表示该方法返回的实例交给spring管理
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}

View File

@ -0,0 +1,31 @@
package cn.czyx007.controller;
import cn.czyx007.bean.Brand;
import cn.czyx007.service.IBrandService;
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.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author zyx
* @since 2023-05-26
*/
@RestController
@RequestMapping("/brand")
public class BrandController {
@Autowired
private IBrandService brandService;
@GetMapping("/getBrand")
public List<Brand> getBrand(){
System.out.println("yeeee周五了");
return brandService.list();
}
}

View File

@ -0,0 +1,33 @@
package cn.czyx007.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author : 张宇轩
* @createTime : 2023/5/26 - 16:07
*/
public class MyInterceptor implements HandlerInterceptor {
//请求到达控制器之前执行此方法
//返回true请求通过否则不通过
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("preHandle执行...");
return true;
}
//请求已经到达了控制器执行此方法
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
System.out.println("postHandle执行...");
}
//请求完成之后执行此方法
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
System.out.println("afterCompletion执行...");
}
}

View File

@ -0,0 +1,18 @@
package cn.czyx007.mapper;
import cn.czyx007.bean.Brand;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author zyx
* @since 2023-05-26
*/
@Mapper
public interface BrandMapper extends BaseMapper<Brand> {
}

View File

@ -0,0 +1,14 @@
package cn.czyx007.mapper;
import cn.czyx007.bean.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 15:30
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

View File

@ -0,0 +1,16 @@
package cn.czyx007.service;
import cn.czyx007.bean.Brand;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author zyx
* @since 2023-05-26
*/
public interface IBrandService extends IService<Brand> {
}

View File

@ -0,0 +1,12 @@
package cn.czyx007.service;
import cn.czyx007.bean.User;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author : 张宇轩
* @createTime : 2023/5/26 - 11:35
*/
public interface UserService extends IService<User> {
}

View File

@ -0,0 +1,20 @@
package cn.czyx007.service.impl;
import cn.czyx007.bean.Brand;
import cn.czyx007.mapper.BrandMapper;
import cn.czyx007.service.IBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author zyx
* @since 2023-05-26
*/
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {
}

View File

@ -0,0 +1,18 @@
package cn.czyx007.service.impl;
import cn.czyx007.bean.User;
import cn.czyx007.mapper.UserMapper;
import cn.czyx007.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author : 张宇轩
* @createTime : 2023/5/26 - 11:38
*/
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}

View File

@ -0,0 +1,28 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/person_info?serverTimezone=Asia/Shanghai
username: root
password: zyx007
druid:
#初始化连接数
initial-size: 1
#最小空闲连接
min-idle: 1
#最大活动连接
max-active: 20
#获取连接时测试是否可用
test-on-borrow: true
#监控页面启动
filter:
wall:
config:
start-transaction-allow: true
# web:
# resources:
# #修改静态资源目录
# static-locations: classpath:/liuyan/
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB

View File

@ -0,0 +1,84 @@
package cn.czyx007;
import cn.czyx007.bean.User;
import cn.czyx007.mapper.UserMapper;
import cn.czyx007.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.mysql.cj.util.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Collections;
import java.util.List;
@SpringBootTest
class ApplicationTests {
@Autowired
private UserMapper userMapper;
@Autowired
private UserService userService;
@Test
void contextLoads() {
List<User> users = userMapper.selectList(null);
users.forEach(System.out::println);
}
@Test
void test2(){
String name = "J";
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.like(!StringUtils.isNullOrEmpty(name), User::getName, name);
List<User> user = userMapper.selectList(lqw);
user.forEach(System.out::println);
}
@Test
void test3(){
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.like(User::getName, "J");
userService.list(lqw).forEach(System.out::println);
}
@Test
void test4(){
//创建一个mybatisplus的分页对象
IPage<User> iPage = new Page<>(1, 2);
//进行查询
userService.page(iPage);
//输出结果
System.out.println("分页数据:" + iPage.getRecords());
System.out.println("页数:" + iPage.getPages());
System.out.println("记录数:" + iPage.getTotal());
}
@Test
void test5(){
FastAutoGenerator.create("jdbc:mysql://localhost:3306/person_info?serverTimezone=Asia/Shanghai",
"root", "zyx007")
.globalConfig(builder -> {
builder.author("zyx") // 设置作者
// .enableSwagger() // 开启 swagger 模式
.outputDir("C:\\Users\\zyx\\Desktop\\课程文件\\大三\\下学期\\生产实习\\ProductionPractice\\springboot-mbp-526\\src\\main\\java\\cn\\czyx007"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("demo") // 设置父包名
// .moduleName("system") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.xml, "C:\\Users\\zyx\\Desktop\\课程文件\\大三\\下学期\\生产实习\\ProductionPractice\\springboot-mbp-526\\src\\main\\resources\\mappers")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("tb_brand") // 设置需要生成的表名
.addTablePrefix("tb_"); // 设置过滤表前缀
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板默认的是Velocity引擎模板
.execute();
}
}

View File

@ -9,10 +9,10 @@
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.example</groupId> <groupId>com.example</groupId>
<artifactId>springboot525</artifactId> <artifactId>springboot525-526</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>springboot525</name> <name>springboot525-526</name>
<description>springboot525</description> <description>springboot525-526</description>
<properties> <properties>
<java.version>11</java.version> <java.version>11</java.version>
</properties> </properties>
@ -42,6 +42,11 @@
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version> <version>2.2.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -11,5 +11,11 @@ mybatis:
configuration: configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
person: person:
username: abc username: abc

View File

@ -0,0 +1,32 @@
package cn.czyx007;
import cn.czyx007.bean.User;
import cn.czyx007.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class ApplicationTests {
@Autowired
private UserService userService;
@Test
void contextLoads() {
//开启分页查询
PageHelper.startPage(1,2);
//查询数据
List<User> user = userService.findUser();
PageInfo<User> pageInfo = new PageInfo<>(user);
List<User> list = pageInfo.getList();
list.forEach(System.out::println);
System.out.println("页数 = " + pageInfo.getPages());
}
}

View File

@ -1,14 +0,0 @@
package cn.czyx007;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ApplicationTests {
@Test
void contextLoads() {
}
}