IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> SpringBoot + MyBatis-Plus +MySQL8 +Thymeleaf +LayUI通用业务模块增删改查 -> 正文阅读

[Java知识库]SpringBoot + MyBatis-Plus +MySQL8 +Thymeleaf +LayUI通用业务模块增删改查

目录

1、基础技术框架

2、完整pom.xml??

3、初始化脚本

4、功能效果截图

5、项目结构截图:?

6、业务模块说明

?7、通用模块说明

?8、系统初始化配置和程序入口

?9:源码下载地址


1、基础技术框架

技术名称版本
SpringBoot2.1.0.RELEASE
Mybatis-Plus3.4.1
Lombok1.18.2
MySQL88.0.13
Alibaba?Druid1.1.10
Thymelaf3.0.11
Alibaba Fastjson1.2.4
Hutool5.5.2

2、完整pom.xml??

<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>
	<groupId>com.zzg</groupId>
	<artifactId>cas-thymeleaf</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.0.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<encoding>UTF-8</encoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<!--starter -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<!-- test -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<!--web -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!--validation -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>
		<!-- MyBatis-Plus 拓展 -->
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.4.1</version>
		</dependency>
		<!--lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
		</dependency>

		<!--mysql-connector -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
		<!-- druid-spring-boot-starter -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid-spring-boot-starter</artifactId>
			<version>1.1.10</version>
		</dependency>
		<!-- 集成thymelaf -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<!-- commons-lang -->
		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.6</version>
		</dependency>
		<!-- apache common 模块 -->
		<!--commons-lang3 工具包 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.9</version>
		</dependency>
		<!--commons-codec 加密工具包 -->
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.10</version>
		</dependency>
		<!--commons-net 网络工具包 -->
		<dependency>
			<groupId>commons-net</groupId>
			<artifactId>commons-net</artifactId>
			<version>3.6</version>
		</dependency>
		<!--common-io 工具包 -->
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.6</version>
		</dependency>
		<!--common-collection 工具包 -->
		<dependency>
			<groupId>commons-collections</groupId>
			<artifactId>commons-collections</artifactId>
			<version>3.2.1</version>
		</dependency>
		<!-- 集成fastjson -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.4</version>
		</dependency>
		<!-- 集成hutool-all 工具包 -->
		<dependency>
			<groupId>cn.hutool</groupId>
			<artifactId>hutool-all</artifactId>
			<version>5.5.2</version>
		</dependency>


	</dependencies>
</project>

3、初始化脚本

CREATE TABLE IF NOT EXISTS `employee` (
  `id` int(32) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `code` varchar(32) NOT NULL COMMENT '员工编号',
  `name` varchar(64) NOT NULL COMMENT '员工名称',
  `sex` int(2) NOT NULL DEFAULT '1' COMMENT '性别:1:男(默认) 2:女',
  `birthday` datetime NOT NULL COMMENT '出生日期',
  `passwd` varchar(32) NOT NULL COMMENT '员工密码',
  `telephone` varchar(32) NOT NULL COMMENT '电话',
  `note` varchar(128) DEFAULT NULL COMMENT '备注',
  `work_year` int(2) NOT NULL COMMENT '工作年限',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='员工表';

4、功能效果截图

5、项目结构截图:?

6、业务模块说明

com.zzg.entity = 实体对象定义

com.zzg.mapper= 接口映射

com.zzg.service= 服务定义

com.zzg.service.impl= 服务实列化

com.zzg.controller=业务控制层

package com.zzg.entity;                                                                                                         
                                                                                                                                
import java.util.Date;                                                                                                          
                                                                                                                                
import org.springframework.format.annotation.DateTimeFormat;                                                                    
                                                                                                                                
import com.baomidou.mybatisplus.annotation.FieldFill;                                                                           
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.Data;                                                                                                             
                                                                                                                                
@Data                                                                                                                           
@TableName                                                                                                                      
public class Employee {                                                                                                         
	@TableId(type=IdType.AUTO)                                                                                                  
    private Integer id;                                                                                                         
                                                                                                                                
    private String code;                                                                                                        
                                                                                                                                
    private String name;                                                                                                        
                                                                                                                                
    private Integer sex;                                                                                                        
                                                                                                                                
    @DateTimeFormat(pattern = "yyyy-MM-dd")                                                                                     
    private Date birthday;                                                                                                      
                                                                                                                                
    private String passwd;                                                                                                      
                                                                                                                                
    private String telephone;                                                                                                   
                                                                                                                                
    @TableField(fill = FieldFill.DEFAULT)                                                                                       
    private String note;                                                                                                        
                                                                                                                                
    private Integer workYear;                                                                                                   
                                                                                                                                
                                                                                                                                
}                                                                                                                               
package com.zzg.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzg.entity.Employee;

public interface EmployeeMapper extends BaseMapper<Employee> {
}
package com.zzg.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zzg.entity.Employee;


public interface EmployeeService extends IService<Employee> {

}
package com.zzg.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzg.entity.Employee;
import com.zzg.mapper.EmployeeMapper;
import com.zzg.service.EmployeeService;

@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

}
package com.zzg.controller;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzg.common.AbstractCommonController;
import com.zzg.common.Response;
import com.zzg.entity.Employee;
import com.zzg.service.EmployeeService;

@Controller
@RequestMapping("/employee")
public class EmployeeController extends AbstractCommonController<Employee> {
	@Autowired
	private EmployeeService service;
	
	@GetMapping(value = "/list")
	public String view() {
		return "page/sys/employeeList";
	}
	@GetMapping(value = "/add")
	public String add() {
		return "page/sys/employeeAdd";
	}
	
	
	 // 增
	@RequestMapping(value = "save")
	@ResponseBody
    public Response<Boolean> save(Employee employe) {
    	Boolean target = service.save(employe);
        return Response.success(target);
    }
    
    @RequestMapping(value = "edit")
	public String edit(Employee employee, Model model) {
		model.addAttribute("employee", service.getById(employee.getId()));
		return "page/sys/employeeEdit";
	}

    // 改
    @RequestMapping(value = "update")
	@ResponseBody
    public Response<Boolean> update(Employee employee ) {
        return Response.success(service.updateById(employee));
    }

    // 删
    @RequestMapping(value = "delete")
	@ResponseBody
    public Response<Boolean> delete( Employee employee ) {
        return Response.success(service.removeById(employee.getId()));
    }

    // 查
    @GetMapping( value = "/getUserByName")
    public Object getUserByName( @RequestParam String userName ) {
    	QueryWrapper<Employee> wrapper =new QueryWrapper<Employee>() ;
    	wrapper.like("name", userName);
        return service.getOne(wrapper);
    }
    
    // 查
    @GetMapping( value = "/page", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object page( @RequestParam(required = false) Map paramter ) {
    	Page<Employee> page = super.getPage(paramter);
    	QueryWrapper<Employee> wrapper =new QueryWrapper<Employee>() ;
    	
    	if(paramter.get("id") != null && StringUtils.isNotEmpty(paramter.get("id").toString())) {
    		wrapper.eq(true, "id", paramter.get("id"));
    	}
    	if(paramter.get("name") != null && StringUtils.isNotEmpty(paramter.get("name").toString())) {
    		wrapper.like(true, "name", paramter.get("name"));
    	}
    	if(paramter.get("code") != null && StringUtils.isNotEmpty(paramter.get("code").toString())) {
    		wrapper.like(true, "code", paramter.get("code"));
    	}
    	IPage<Employee> result = service.page(page, wrapper);
        return result;
    }
    
    
}


?

package com.zzg.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 系统首页Controller
 * 
 * @author zzg
 *
 */
@Controller
public class IndexController {
	/**
	 * 首页
	 * 
	 * @return
	 */
	@GetMapping(value = "index")
	public String index(Model model) {
		model.addAttribute("user", "周志刚");
		return "index";
	}
	
	/**
	 * 控制台
	 * 
	 * @return
	 */
	@GetMapping(value = "view")
	public String view() {
		return "page/sys/view";
	}
}

?7、通用模块说明

package com.zzg.common.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.util.NumberUtils;

public class ObjectToIntegerConverterFactory implements ConverterFactory<Integer, Integer> {

	public <T extends Integer> Converter<Integer, T> getConverter(Class<T> targetType) {
		// TODO Auto-generated method stub
		return new ObjectToInteger(targetType);
	}
	
	// 私有内部类:实现Converter接口。用泛型边界约束一类类型
		private static final class ObjectToInteger<T extends Integer> implements Converter<T, Integer> {

			private final Class<T> targetType;
			public ObjectToInteger(Class<T> targetType) {
				this.targetType = targetType;
			}


			public Integer convert(T source) {
				// TODO Auto-generated method stub
				if(source == null) {
					return 0;
				}
				return NumberUtils.parseNumber(String.valueOf(source), this.targetType);
			}
		}

}

package com.zzg.common;

import java.util.Map;

import org.springframework.core.convert.converter.ConverterFactory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzg.common.converter.ObjectToIntegerConverterFactory;

public abstract class AbstractCommonController<T> {
	public static final String pageNo = "pageNo";
	public static final String pageSize = "pageSize";
	public Page<T> getPage(Map map){
		ConverterFactory<Integer, Integer> converterFactory = new ObjectToIntegerConverterFactory();
		Integer no = converterFactory.getConverter(Integer.class).convert(Integer.valueOf(String.valueOf(map.get(pageNo))));
		Integer size = converterFactory.getConverter(Integer.class).convert(Integer.valueOf(String.valueOf(map.get(pageSize))));
		return new Page<T>(no,size);
	}
	
	
}

package com.zzg.common;

import java.io.PrintWriter;

import javax.servlet.ServletResponse;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Response<T> {
	/**
	 * 响应码
	 */
	private int code;
 
	/**
	 * 响应消息体
	 */
	private String msg;
 
	/**
	 * 响应数据
	 */
	private T data;
 
	/**
	 * 失败响应
	 * 
	 * @param code 响应码
	 * @param msg  响应消息体
	 * @param data 响应数据
	 * @return
	 */
	public static <T> Response<T> error(int code, String msg, T data) {
		return new Response<T>(code, msg, data);
	}
 
	/**
	 * 失败响应
	 * 
	 * @param msg 响应消息体
	 * @return
	 */
	public static <T> Response<T> error(String msg) {
		return new Response<T>(500, msg, null);
	}
 
	/**
	 * 成功响应
	 * 
	 * @param data 响应数据
	 * @return
	 */
	public static <T> Response<T> success(T data) {
		return new Response<T>(200, null, data);
	}
 
	/**
	 * 成功响应
	 * 
	 * @param msg 响应消息体
	 * @return
	 */
	public static <T> Response<T> success(String msg) {
		return new Response<T>(200, msg, null);
	}
 
	/**
	 * 成功响应
	 * 
	 * @param msg  响应消息体
	 * @param data 响应数据
	 * @return
	 */
	public static <T> Response<T> success(String msg, T data) {
		return new Response<T>(200, msg, data);
	}
 
	/**
	 * Response输出Json格式
	 * 
	 * @param response
	 * @param data     返回数据
	 */
	public static void responseJson(ServletResponse response, Object data) {
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/json");
			out = response.getWriter();
			out.println(JSONUtil.toJsonStr(data));
			out.flush();
		} catch (Exception e) {
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}

}

?8、系统初始化配置和程序入口

package com.zzg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
/**
 * MyBatisPlus 配置类
 * @author Administrator
 *
 */
@Configuration
public class MyBatisPlusConfig {
	 /**
     * 分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }


}

package com.zzg;

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

@SpringBootApplication
@MapperScan("com.zzg.mapper")
public class DemoApplication {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpringApplication.run(DemoApplication.class, args);
	}

}

?9:源码下载地址

链接:https://pan.baidu.com/s/1WN0k3oaMRMP1xV3r2nbIXg?
提取码:zcxy?

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2021-12-26 22:00:25  更:2021-12-26 22:00:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 7:47:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码