Browse Source

init & crud

master
mail_yanpeng@163.com 4 years ago
commit
daf9712612
  1. 34
      .gitignore
  2. 35
      build.gradle
  3. 1
      settings.gradle
  4. 24
      src/main/java/com/aiprose/mbp/MbpApplication.java
  5. 38
      src/main/java/com/aiprose/mbp/conf/SwaggerConfiguration.java
  6. 37
      src/main/java/com/aiprose/mbp/conf/WebMvcConfig.java
  7. 27
      src/main/java/com/aiprose/mbp/controller/UserController.java
  8. 33
      src/main/java/com/aiprose/mbp/entity/SuperEntity.java
  9. 26
      src/main/java/com/aiprose/mbp/entity/User.java
  10. 15
      src/main/java/com/aiprose/mbp/mapper/UserMapper.java
  11. 26
      src/main/java/com/aiprose/mbp/service/UserService.java
  12. 23
      src/main/resources/application.yml
  13. 13
      src/test/java/com/aiprose/mbp/MbpApplicationTests.java

34
.gitignore

@ -0,0 +1,34 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/

35
build.gradle

@ -0,0 +1,35 @@
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.aiprose'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.3.2'
compile group: 'com.gitee.sunchenbin.mybatis.actable', name: 'mybatis-enhance-actable', version: '1.2.1.RELEASE'
// compile group: 'com.github.xiaoymin', name: 'knife4j-spring-boot-starter', version: '2.0.4'
// implementation 'com.github.xiaoymin:knife4j-spring-boot-starter:2.0.2'
}
test {
useJUnitPlatform()
}

1
settings.gradle

@ -0,0 +1 @@
rootProject.name = 'mbp'

24
src/main/java/com/aiprose/mbp/MbpApplication.java

@ -0,0 +1,24 @@
package com.aiprose.mbp;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
//@MapperScan({"com.aiprose.mbp.mapper"})
@MapperScan({"com.aiprose.mbp.mapper","com.gitee.sunchenbin.mybatis.actable.dao.*"})
@ComponentScan({"com.gitee.sunchenbin.mybatis.actable.manager.*","com.aiprose.mbp.*"})
@SpringBootApplication
public class MbpApplication {
public static void main(String[] args) {
SpringApplication.run(MbpApplication.class, args);
}
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}

38
src/main/java/com/aiprose/mbp/conf/SwaggerConfiguration.java

@ -0,0 +1,38 @@
//package com.aiprose.mbp.conf;
//
//import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Import;
//import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
//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
//@EnableKnife4j
//@Import(BeanValidatorPluginsConfiguration.class)
//public class SwaggerConfiguration {
// @Bean
// public Docket createRestApi() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.aiprose.mbp.controller"))
// .paths(PathSelectors.any())
// .build();
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder()
// .title("swagger-bootstrap-ui RESTful APIs")
// .description("swagger-bootstrap-ui")
// .version("1.0")
// .build();
// }
//}

37
src/main/java/com/aiprose/mbp/conf/WebMvcConfig.java

@ -0,0 +1,37 @@
package com.aiprose.mbp.conf;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST","DELETE","OPTIONS")
.allowCredentials(false).maxAge(3600);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/assets/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("doc.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/web/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
}

27
src/main/java/com/aiprose/mbp/controller/UserController.java

@ -0,0 +1,27 @@
package com.aiprose.mbp.controller;
import com.aiprose.mbp.entity.User;
import com.aiprose.mbp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping("save")
public void save() {
User user = new User();
user.setName("nelson");
userService.save(user);
}
@GetMapping("list")
public List<User> user() {
return userService.list();
}
}

33
src/main/java/com/aiprose/mbp/entity/SuperEntity.java

@ -0,0 +1,33 @@
package com.aiprose.mbp.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsAutoIncrement;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class SuperEntity implements Serializable {
/**
* 主键
*/
@TableId(type = IdType.AUTO) //mybatis-plus主键注解
@IsKey //actable主键注解
@IsAutoIncrement //自增
@Column //对应数据库字段,不配置name会直接采用属性名作为字段名
private Long id;
/**
* 创建时间
*/
@Column(name = "create_time",comment = "创建时间") // name指定数据库字段名,comment为备注
private Date createTime = new Date();
/**
* 最后修改时间
*/
@Column(name = "update_time",comment = "最后修改时间")
private Date updateTime;
}

26
src/main/java/com/aiprose/mbp/entity/User.java

@ -0,0 +1,26 @@
package com.aiprose.mbp.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import lombok.Data;
@Data
@Table(name="mbp_user")
@TableName("mbp_user")
public class User extends SuperEntity{
@Column
private String name;
@Column
private Integer age;
@Column
private String email;
public User(){
}
public User(Long id,String name){
this.name = name;
}
}

15
src/main/java/com/aiprose/mbp/mapper/UserMapper.java

@ -0,0 +1,15 @@
package com.aiprose.mbp.mapper;
import com.aiprose.mbp.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface UserMapper extends BaseMapper<User> {
@Select("select * from mbp_user")
public List<User> queryList();
}

26
src/main/java/com/aiprose/mbp/service/UserService.java

@ -0,0 +1,26 @@
package com.aiprose.mbp.service;
import com.aiprose.mbp.entity.User;
import com.aiprose.mbp.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
public User save(User user){
int insert = userMapper.insert(user);
return user;
}
public List<User> list(){
List<User> userList1 = userMapper.queryList();
List<User> userList = userMapper.selectList(null);
return userList;
}
}

23
src/main/resources/application.yml

@ -0,0 +1,23 @@
server:
port: 8200
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.98.109.5:3309/mbp?characterEncoding=utf8&useSSL=false
username: root
password: trgis
hikari:
minimum-idle: 3
maximum-pool-size: 10
max-lifetime: 1800000
connection-test-query: SELECT 1
actable:
table:
auto: update
model:
pack: com.aiprose.mbp.entity
database:
type: mysql
mybatis-plus:
mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
# mapper-locations: classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml

13
src/test/java/com/aiprose/mbp/MbpApplicationTests.java

@ -0,0 +1,13 @@
package com.aiprose.mbp;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MbpApplicationTests {
@Test
void contextLoads() {
}
}
Loading…
Cancel
Save