Browse Source

后端框架第一版接口

Houduan1
huangqizhen 6 months ago
parent
commit
870164a3c7
  1. 2
      demo/commons/src/main/java/com/example/commons/domain/entity/Audit.java
  2. 2
      demo/commons/src/main/java/com/example/commons/domain/entity/Detail.java
  3. 2
      demo/commons/src/main/java/com/example/commons/domain/entity/Recharge.java
  4. 44
      demo/commons/src/main/java/com/example/commons/domain/vo/Result.java
  5. 13
      demo/commons/src/main/java/com/example/commons/sevice/RechargeService.java
  6. 8
      demo/commons/src/main/java/com/example/commons/sevice/UserSevice.java
  7. 6
      demo/pom.xml
  8. 22
      demo/user/src/main/java/com/example/user/controller/UserController.java
  9. 14
      demo/user/src/main/java/com/example/user/mapper/UserMapper.java
  10. 20
      demo/user/src/main/java/com/example/user/service/UserServiceImpl.java
  11. 14
      demo/user/src/main/resources/application.yml

2
demo/commons/src/main/java/com/example/commons/domain/entity/audit.java → demo/commons/src/main/java/com/example/commons/domain/entity/Audit.java

@ -9,7 +9,7 @@ import java.util.Date;
@Data
@NoArgsConstructor
public class audit {
public class Audit {
private Integer auditId;
private Integer homilyId;
private Integer rechargeId;

2
demo/commons/src/main/java/com/example/commons/domain/entity/detail.java → demo/commons/src/main/java/com/example/commons/domain/entity/Detail.java

@ -9,7 +9,7 @@ import java.util.Date;
@Data
@NoArgsConstructor
public class detail {
public class Detail {
private Integer detailId;
private String name;
private String homilyId;

2
demo/commons/src/main/java/com/example/commons/domain/entity/recharge.java → demo/commons/src/main/java/com/example/commons/domain/entity/Recharge.java

@ -9,7 +9,7 @@ import java.util.Date;
@Data
@NoArgsConstructor
public class recharge {
public class Recharge {
private Integer rechargeId;
private String homilyId;
private Integer activityId;

44
demo/commons/src/main/java/com/example/commons/domain/vo/Result.java

@ -0,0 +1,44 @@
package com.example.commons.domain.vo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
private Integer code;
private String msg;
private Object data;
public static Result success(Integer code, String msg, Object data) {
return new Result(code, msg, data);
}
public static Result success(Integer code, Object data) {
return success(code, "操作成功", data);
}
public static Result success(Object data){
return success(200, data);
}
public static Result success(){
return success(null);
}
public static Result error(Integer code, String msg, Object data){
return new Result(code, msg, data);
}
public static Result error(Integer code, String msg){
return error(code, msg, null);
}
public static Result error(String msg){
return error(0, msg);
}
public String toJson() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
}
}

13
demo/commons/src/main/java/com/example/commons/sevice/RechargeService.java

@ -0,0 +1,13 @@
package com.example.commons.sevice;
import com.example.commons.domain.entity.Recharge;
import java.util.List;
public interface RechargeService {
int add(Recharge recharge) throws Exception;
int edit(Recharge recharge) throws Exception;
Recharge findById(int id) throws Exception;
List<Recharge> findAll() throws Exception;
}

8
demo/commons/src/main/java/com/example/commons/sevice/UserSevice.java

@ -0,0 +1,8 @@
package com.example.commons.sevice;
import com.example.commons.domain.entity.User;
public interface UserSevice {
User getByHomilyId(String homilyId);
}

6
demo/pom.xml

@ -20,6 +20,7 @@
<modules>
<module>recharge</module>
<module>commons</module>
<module>user</module>
</modules>
<properties>
@ -34,6 +35,11 @@
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>

22
demo/user/src/main/java/com/example/user/controller/UserController.java

@ -0,0 +1,22 @@
package com.example.user.controller;
import com.example.commons.domain.vo.Result;
import com.example.commons.sevice.UserSevice;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/recharge/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {
private final UserSevice userSevice;
@PostMapping("/{id}")
public Result getUser(@PathVariable String id) {
return Result.success(userSevice.getByHomilyId(id));
}
}

14
demo/user/src/main/java/com/example/user/mapper/UserMapper.java

@ -0,0 +1,14 @@
package com.example.user.mapper;
import com.example.commons.domain.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface UserMapper {
@Select({
"select * from user",
"where homilyId=#{homily_id}"
})
User getByHomilyId(String homilyId);
}

20
demo/user/src/main/java/com/example/user/service/UserServiceImpl.java

@ -0,0 +1,20 @@
package com.example.user.service;
import com.example.commons.domain.entity.User;
import com.example.commons.sevice.UserSevice;
import com.example.user.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserSevice {
private final UserMapper userMapper;
@Override
public User getByHomilyId(String homilyId) {
return userMapper.getByHomilyId(homilyId);
}
}

14
demo/user/src/main/resources/application.yml

@ -0,0 +1,14 @@
server:
port: 10020
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.101.133.168/hwgold?serverTimezone=GMT%2b8
username: hwgold
password: 'AGX4Z3YMxiCG3GR2'
application:
name: recharge
mybatis:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Loading…
Cancel
Save