mirror of
https://github.com/dairuoqi/Springboot-rock-admin.git
synced 2026-10-22 10:33:40 +00:00
Init
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/build/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
@@ -0,0 +1,113 @@
|
||||
<?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>
|
||||
|
||||
<groupId>com.rock</groupId>
|
||||
<artifactId>geological</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>geological</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.30</version>
|
||||
</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>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-rest-core</artifactId>
|
||||
<version>3.0.7.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-base</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-web</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-annotation</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- druid数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.29</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.rock.geological;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
public class GeologicalApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GeologicalApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.rock.geological.aop;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
/**
|
||||
* 请求日志拦截器
|
||||
*/
|
||||
public class WebLogAspect {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
ThreadLocal<Long> startTime = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 定义一个切入点.
|
||||
* ~ 第一个 * 代表任意修饰符及任意返回值.
|
||||
* ~ 第二个 * 任意包名
|
||||
* ~ 第三个 * 代表任意方法.
|
||||
* ~ 第四个 * 定义在web包或者子包
|
||||
* ~ 第五个 * 任意方法
|
||||
* ~ .. 匹配任意数量的参数.
|
||||
*/
|
||||
@Pointcut("execution(public * com.rock.geological.web.controller.*.*(..))")
|
||||
public void webLog() {}
|
||||
|
||||
|
||||
@Before("webLog()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
startTime.set(System.currentTimeMillis());
|
||||
// 接收到请求,记录请求内容
|
||||
logger.info("===== {{ WebLogAspect.doBefore() }} ===== ");
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
// 记录下请求内容
|
||||
logger.info("URL : " + request.getRequestURL().toString() + " , HTTP_METHOD : " + request.getMethod());
|
||||
logger.info("IP : " + request.getRemoteAddr());
|
||||
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
|
||||
logger.info("PARAMS : " + Arrays.toString(joinPoint.getArgs()));
|
||||
}
|
||||
|
||||
|
||||
@AfterReturning(returning = "ret", pointcut = "webLog()")
|
||||
public void doAfterReturning(Object ret) {
|
||||
// 处理完请求,返回内容
|
||||
logger.info("===== {{ WebLogAspect.doAfterReturning() }} =====");
|
||||
logger.info("RESPONSE : " + ret);
|
||||
logger.info("SPEND TIME : " + (System.currentTimeMillis() - startTime.get()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.rock.geological.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.http.StatViewServlet;
|
||||
import com.alibaba.druid.support.http.WebStatFilter;
|
||||
import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
|
||||
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.JdkRegexpMethodPointcut;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class DruidConfiguration {
|
||||
|
||||
//使用连接池dataSource
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "spring.datasource")
|
||||
public DataSource dataSource() {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
return druidDataSource;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean statViewServlet() {
|
||||
// 创建servlet注册实体
|
||||
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),
|
||||
"/druid/*");
|
||||
// 设置ip白名单
|
||||
servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
|
||||
// 设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
|
||||
servletRegistrationBean.addInitParameter("deny", "192.168.0.1");
|
||||
// 设置控制台管理用户
|
||||
servletRegistrationBean.addInitParameter("loginUsername", "admin");
|
||||
servletRegistrationBean.addInitParameter("loginPassword", "123456");
|
||||
// 是否可以重置数据
|
||||
servletRegistrationBean.addInitParameter("resetEnable", "false");
|
||||
return servletRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean statFilter() {
|
||||
// 创建过滤器
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
|
||||
// 设置过滤器过滤路径
|
||||
filterRegistrationBean.addUrlPatterns("/*");
|
||||
// 忽略过滤的形式
|
||||
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JdkRegexpMethodPointcut druidStatPointcut() {
|
||||
JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut();
|
||||
String patterns = "com.rock.geological.web.*.service.*";
|
||||
//可以set多个
|
||||
druidStatPointcut.setPatterns(patterns);
|
||||
return druidStatPointcut;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Advisor druidStatAdvisor() {
|
||||
return new DefaultPointcutAdvisor(druidStatPointcut(), druidStatInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DruidStatInterceptor druidStatInterceptor() {
|
||||
return new DruidStatInterceptor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.rock.geological.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
// 自行修改为自己的包路径
|
||||
.apis(RequestHandlerSelectors.basePackage("com.rock.geological.web.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("api文档")
|
||||
.description("restful 风格接口")
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.rock.geological.utils;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import com.sun.deploy.net.URLEncoder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExcelUtils {
|
||||
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName, boolean isCreateHeader, HttpServletResponse response) {
|
||||
ExportParams exportParams = new ExportParams(title, sheetName);
|
||||
exportParams.setCreateHeadRows(isCreateHeader);
|
||||
defaultExport(list, pojoClass, fileName, response, exportParams);
|
||||
|
||||
}
|
||||
|
||||
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName, HttpServletResponse response) {
|
||||
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
|
||||
}
|
||||
|
||||
public static void exportExcel(List<Map<String, Object>> list, String fileName, HttpServletResponse response) {
|
||||
defaultExport(list, fileName, response);
|
||||
}
|
||||
|
||||
private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response, ExportParams exportParams) {
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
|
||||
if (workbook != null) ;
|
||||
downLoadExcel(fileName, response, workbook);
|
||||
}
|
||||
|
||||
private static void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) {
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
workbook.write(response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void defaultExport(List<Map<String, Object>> list, String fileName, HttpServletResponse response) {
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(list, ExcelType.HSSF);
|
||||
if (workbook != null) ;
|
||||
downLoadExcel(fileName, response, workbook);
|
||||
}
|
||||
|
||||
public static <T> List<T> importExcel(String filePath, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = null;
|
||||
try {
|
||||
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = null;
|
||||
try {
|
||||
list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.rock.geological.web.controller;
|
||||
|
||||
import com.rock.geological.utils.ExcelUtils;
|
||||
import com.rock.geological.web.pojo.User;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ExportController {
|
||||
@GetMapping("export")
|
||||
public void export(HttpServletResponse response){
|
||||
|
||||
//模拟从数据库获取需要导出的数据
|
||||
List<User> personList = new ArrayList<>();
|
||||
User person1 = new User();
|
||||
person1.setUsername("dai");
|
||||
personList.add(person1);
|
||||
//导出操作
|
||||
ExcelUtils.exportExcel(personList,"花名册","草帽一伙",User.class,"海贼王.xls",response);
|
||||
}
|
||||
|
||||
@PutMapping("importExcel")
|
||||
public void importExcel(){
|
||||
String filePath = "/Users/rock/Desktop/现阶段须二岩性图odd.xls";
|
||||
//解析excel,
|
||||
List<User> personList = ExcelUtils.importExcel(filePath,1,1,User.class);
|
||||
//也可以使用MultipartFile,使用 FileUtil.importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass)导入
|
||||
System.out.println("导入数据一共【"+personList.size()+"】行");
|
||||
//TODO 保存数据库
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.rock.geological.web.controller;
|
||||
|
||||
import com.rock.geological.web.pojo.User;
|
||||
import com.rock.geological.web.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
//查询所有
|
||||
@GetMapping("/findAll")
|
||||
public List<User> findAll() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getUserByName")
|
||||
public ResponseEntity<?> getUserByName(String userName) {
|
||||
User user = userService.findUserByName(userName);
|
||||
return ResponseEntity.ok(user);
|
||||
}
|
||||
|
||||
//添加
|
||||
@PostMapping("/save")
|
||||
public void register(@RequestBody User user) {
|
||||
userService.save(user);
|
||||
}
|
||||
|
||||
//删除
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public void delete(@PathVariable Integer id) {
|
||||
userService.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.rock.geological.web.dao;
|
||||
|
||||
|
||||
import com.rock.geological.web.pojo.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
public interface UserDao extends CrudRepository<User, Integer> {
|
||||
|
||||
/*根据用户名称查询用户*/
|
||||
@Query(value = "select * from user where username= ?1", nativeQuery = true)
|
||||
User findUserByName(String userName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.rock.geological.web.pojo;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@Excel(name = "姓名", orderNum = "0")
|
||||
private String username;
|
||||
@Excel(name = "姓名", orderNum = "0")
|
||||
private String salt;
|
||||
@Excel(name = "姓名", orderNum = "0")
|
||||
private String password;
|
||||
|
||||
private String updateUser;
|
||||
|
||||
private Timestamp updateTime;
|
||||
|
||||
private String createUser;
|
||||
|
||||
private Timestamp createTime;
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUpdateUser() {
|
||||
return updateUser;
|
||||
}
|
||||
|
||||
public void setUpdateUser(String updateUser) {
|
||||
this.updateUser = updateUser;
|
||||
}
|
||||
|
||||
public Timestamp getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Timestamp updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getCreateUser() {
|
||||
return createUser;
|
||||
}
|
||||
|
||||
public void setCreateUser(String createUser) {
|
||||
this.createUser = createUser;
|
||||
}
|
||||
|
||||
public Timestamp getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Timestamp createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.rock.geological.web.service;
|
||||
|
||||
import com.rock.geological.web.pojo.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User findUserByName(String userName);
|
||||
|
||||
void save(User user);
|
||||
|
||||
|
||||
void delete(Integer id);
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.rock.geological.web.service;
|
||||
|
||||
import com.rock.geological.web.dao.UserDao;
|
||||
import com.rock.geological.web.pojo.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Override
|
||||
public User findUserByName(String userName) {
|
||||
return userDao.findUserByName(userName);
|
||||
}
|
||||
|
||||
public void save(User user){
|
||||
userDao.save(user);
|
||||
}
|
||||
|
||||
|
||||
public void delete(Integer id) {
|
||||
userDao.deleteById(id);
|
||||
}
|
||||
|
||||
public List<User> findAll(){
|
||||
return (List<User>) userDao.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/geological
|
||||
username: root
|
||||
password: drq2028701
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
testOnReturn: false
|
||||
testOnBorrow: false
|
||||
testWhileIdle: true
|
||||
# 下面为连接池的补充设置,应用到上面所有数据源中
|
||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||
filters: stat, wall, log4j
|
||||
dbcp2:
|
||||
min-idle: 5
|
||||
initial-size: 5
|
||||
max-total: 5
|
||||
max-wait-millis: 200
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
#connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
# 实体类有更新时,数据库表更新
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
format_sql: true
|
||||
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.rock.geological;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class GeologicalApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user