dsc 7 months ago
parent c16be78eee
commit c7f707af80

@ -2,18 +2,43 @@ package com.example.common;
import com.example.common.enums.ResultCodeEnum; import com.example.common.enums.ResultCodeEnum;
/**
*
*/
public class Result { public class Result {
/**
*
*/
private String code; private String code;
/**
*
*/
private String msg; private String msg;
/**
*
*/
private Object data; private Object data;
/**
*
*
* @param data
*/
private Result(Object data) { private Result(Object data) {
this.data = data; this.data = data;
} }
/**
*
*/
public Result() { public Result() {
} }
/**
*
*
* @return
*/
public static Result success() { public static Result success() {
Result tResult = new Result(); Result tResult = new Result();
tResult.setCode(ResultCodeEnum.SUCCESS.code); tResult.setCode(ResultCodeEnum.SUCCESS.code);
@ -21,13 +46,24 @@ public class Result {
return tResult; return tResult;
} }
/**
*
*
* @param data
* @return
*/
public static Result success(Object data) { public static Result success(Object data) {
Result tResult = new Result (data); Result tResult = new Result(data);
tResult.setCode(ResultCodeEnum.SUCCESS.code); tResult.setCode(ResultCodeEnum.SUCCESS.code);
tResult.setMsg(ResultCodeEnum.SUCCESS.msg); tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
return tResult; return tResult;
} }
/**
*
*
* @return
*/
public static Result error() { public static Result error() {
Result tResult = new Result(); Result tResult = new Result();
tResult.setCode(ResultCodeEnum.SYSTEM_ERROR.code); tResult.setCode(ResultCodeEnum.SYSTEM_ERROR.code);
@ -35,6 +71,13 @@ public class Result {
return tResult; return tResult;
} }
/**
*
*
* @param code
* @param msg
* @return
*/
public static Result error(String code, String msg) { public static Result error(String code, String msg) {
Result tResult = new Result(); Result tResult = new Result();
tResult.setCode(code); tResult.setCode(code);
@ -42,6 +85,12 @@ public class Result {
return tResult; return tResult;
} }
/**
*
*
* @param resultCodeEnum
* @return
*/
public static Result error(ResultCodeEnum resultCodeEnum) { public static Result error(ResultCodeEnum resultCodeEnum) {
Result tResult = new Result(); Result tResult = new Result();
tResult.setCode(resultCodeEnum.code); tResult.setCode(resultCodeEnum.code);
@ -49,26 +98,56 @@ public class Result {
return tResult; return tResult;
} }
/**
*
*
* @return
*/
public String getCode() { public String getCode() {
return code; return code;
} }
/**
*
*
* @param code
*/
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
/**
*
*
* @return
*/
public String getMsg() { public String getMsg() {
return msg; return msg;
} }
/**
*
*
* @param msg
*/
public void setMsg(String msg) { public void setMsg(String msg) {
this.msg = msg; this.msg = msg;
} }
/**
*
*
* @return
*/
public Object getData() { public Object getData() {
return data; return data;
} }
/**
*
*
* @param data
*/
public void setData(Object data) { public void setData(Object data) {
this.data = data; this.data = data;
} }

@ -7,19 +7,34 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter; import org.springframework.web.filter.CorsFilter;
/** /**
* *
*/ */
@Configuration @Configuration
public class CorsConfig { public class CorsConfig {
/**
*
*
*
*
*
* @return CorsFilter
*/
@Bean @Bean
public CorsFilter corsFilter() { public CorsFilter corsFilter() {
// 创建URL基于的跨域配置源
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// 创建跨域配置对象
CorsConfiguration corsConfiguration = new CorsConfiguration(); CorsConfiguration corsConfiguration = new CorsConfiguration();
// 设置允许任何源进行跨域请求
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址 corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
// 设置允许任何请求头进行跨域请求
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头 corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
// 设置允许任何请求方法进行跨域请求
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法 corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
// 将跨域配置应用到所有路径
source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置 source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
// 返回跨域过滤器实例
return new CorsFilter(source); return new CorsFilter(source);
} }
} }

@ -36,6 +36,16 @@ public class JwtInterceptor implements HandlerInterceptor {
private BusinessService businessService; private BusinessService businessService;
@Resource @Resource
private UserService userService; private UserService userService;
/**
*
*
* @param request
* @param response
* @param handler
* @return
* @throws Exception
*/
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 1. 从http请求的header中获取token // 1. 从http请求的header中获取token
@ -46,6 +56,7 @@ public class JwtInterceptor implements HandlerInterceptor {
} }
// 2. 开始执行认证 // 2. 开始执行认证
if (ObjectUtil.isEmpty(token)) { if (ObjectUtil.isEmpty(token)) {
// 如果仍然没有拿到token抛出异常提示token无效
throw new CustomException(ResultCodeEnum.TOKEN_INVALID_ERROR); throw new CustomException(ResultCodeEnum.TOKEN_INVALID_ERROR);
} }
Account account = null; Account account = null;
@ -65,9 +76,11 @@ public class JwtInterceptor implements HandlerInterceptor {
account = userService.selectById(Integer.valueOf(userId)); account = userService.selectById(Integer.valueOf(userId));
} }
} catch (Exception e) { } catch (Exception e) {
// 如果解析token或者查询用户信息出错抛出异常提示token验证失败
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR); throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
} }
if (ObjectUtil.isNull(account)) { if (ObjectUtil.isNull(account)) {
// 如果用户信息为空,抛出异常,提示用户不存在
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR); throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
} }
try { try {
@ -75,8 +88,9 @@ public class JwtInterceptor implements HandlerInterceptor {
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(account.getPassword())).build(); JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(account.getPassword())).build();
jwtVerifier.verify(token); // 验证token jwtVerifier.verify(token); // 验证token
} catch (JWTVerificationException e) { } catch (JWTVerificationException e) {
// 如果token验证失败抛出异常提示token验证失败
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR); throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
} }
return true; return true;
} }
} }

@ -6,19 +6,29 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource; import javax.annotation.Resource;
/**
* Web
*/
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
// 注入JwtInterceptor拦截器
@Resource @Resource
private JwtInterceptor jwtInterceptor; private JwtInterceptor jwtInterceptor;
/**
*
*
* @param registry
*/
// 加自定义拦截器JwtInterceptor设置拦截规则 // 加自定义拦截器JwtInterceptor设置拦截规则
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
// 设置JwtInterceptor拦截所有路径但排除根路径、登录、注册和文件相关路径
registry.addInterceptor(jwtInterceptor).addPathPatterns("/**") registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
.excludePathPatterns("/") .excludePathPatterns("/")
.excludePathPatterns("/login") .excludePathPatterns("/login")
.excludePathPatterns("/register") .excludePathPatterns("/register")
.excludePathPatterns("/files/**"); .excludePathPatterns("/files/**");
} }
} }

@ -1,25 +1,43 @@
package com.example.common.enums; package com.example.common.enums;
/**
*
*/
public enum ResultCodeEnum { public enum ResultCodeEnum {
// 成功状态
SUCCESS("200", "成功"), SUCCESS("200", "成功"),
// 参数错误相关状态
PARAM_ERROR("400", "参数异常"), PARAM_ERROR("400", "参数异常"),
// Token 相关错误状态
TOKEN_INVALID_ERROR("401", "无效的token"), TOKEN_INVALID_ERROR("401", "无效的token"),
TOKEN_CHECK_ERROR("401", "token验证失败请重新登录"), TOKEN_CHECK_ERROR("401", "token验证失败请重新登录"),
// 参数缺失错误状态
PARAM_LOST_ERROR("4001", "参数缺失"), PARAM_LOST_ERROR("4001", "参数缺失"),
// 系统错误相关状态
SYSTEM_ERROR("500", "系统异常"), SYSTEM_ERROR("500", "系统异常"),
// 用户相关错误状态
USER_EXIST_ERROR("5001", "用户名已存在"), USER_EXIST_ERROR("5001", "用户名已存在"),
USER_NOT_LOGIN("5002", "用户未登录"), USER_NOT_LOGIN("5002", "用户未登录"),
USER_ACCOUNT_ERROR("5003", "账号或密码错误"), USER_ACCOUNT_ERROR("5003", "账号或密码错误"),
USER_NOT_EXIST_ERROR("5004", "用户不存在"), USER_NOT_EXIST_ERROR("5004", "用户不存在"),
PARAM_PASSWORD_ERROR("5005", "原密码输入错误"), PARAM_PASSWORD_ERROR("5005", "原密码输入错误"),
// 业务逻辑相关错误状态
COLLECT_ALREADY_ERROR("5006", "您已收藏过该商品,请勿重复收藏"), COLLECT_ALREADY_ERROR("5006", "您已收藏过该商品,请勿重复收藏"),
; ;
// 状态码
public String code; public String code;
// 状态消息
public String msg; public String msg;
/**
*
*
* @param code
* @param msg
*/
ResultCodeEnum(String code, String msg) { ResultCodeEnum(String code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;

@ -20,7 +20,9 @@ public class AddressController {
private AddressService addressService; private AddressService addressService;
/** /**
* *
* @param address
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Address address) { public Result add(@RequestBody Address address) {
@ -29,7 +31,9 @@ public class AddressController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +42,9 @@ public class AddressController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +53,9 @@ public class AddressController {
} }
/** /**
* *
* @param address
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Address address) { public Result updateById(@RequestBody Address address) {
@ -56,7 +64,9 @@ public class AddressController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -65,7 +75,9 @@ public class AddressController {
} }
/** /**
* *
* @param address
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Address address ) { public Result selectAll(Address address ) {
@ -74,7 +86,11 @@ public class AddressController {
} }
/** /**
* *
* @param address
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Address address, public Result selectPage(Address address,
@ -84,4 +100,4 @@ public class AddressController {
return Result.success(page); return Result.success(page);
} }
} }

@ -19,7 +19,9 @@ public class AdminController {
private AdminService adminService; private AdminService adminService;
/** /**
* *
* @param admin
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Admin admin) { public Result add(@RequestBody Admin admin) {
@ -28,7 +30,9 @@ public class AdminController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -37,7 +41,9 @@ public class AdminController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -46,7 +52,9 @@ public class AdminController {
} }
/** /**
* *
* @param admin
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Admin admin) { public Result updateById(@RequestBody Admin admin) {
@ -55,7 +63,9 @@ public class AdminController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -64,7 +74,9 @@ public class AdminController {
} }
/** /**
* *
* @param admin
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Admin admin ) { public Result selectAll(Admin admin ) {
@ -73,7 +85,11 @@ public class AdminController {
} }
/** /**
* *
* @param admin
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Admin admin, public Result selectPage(Admin admin,
@ -83,4 +99,4 @@ public class AdminController {
return Result.success(page); return Result.success(page);
} }
} }

@ -1,9 +1,7 @@
package com.example.controller; package com.example.controller;
import com.example.common.Result; import com.example.common.Result;
import com.example.entity.Admin;
import com.example.entity.Business; import com.example.entity.Business;
import com.example.service.AdminService;
import com.example.service.BusinessService; import com.example.service.BusinessService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -22,7 +20,9 @@ public class BusinessController {
private BusinessService businessService; private BusinessService businessService;
/** /**
* *
* @param business
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Business business) { public Result add(@RequestBody Business business) {
@ -31,7 +31,9 @@ public class BusinessController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -40,7 +42,9 @@ public class BusinessController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -49,7 +53,9 @@ public class BusinessController {
} }
/** /**
* *
* @param business
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Business business) { public Result updateById(@RequestBody Business business) {
@ -58,7 +64,9 @@ public class BusinessController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -67,7 +75,9 @@ public class BusinessController {
} }
/** /**
* *
* @param business
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Business business ) { public Result selectAll(Business business ) {
@ -76,7 +86,11 @@ public class BusinessController {
} }
/** /**
* *
* @param business
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Business business, public Result selectPage(Business business,
@ -86,4 +100,4 @@ public class BusinessController {
return Result.success(page); return Result.success(page);
} }
} }

@ -20,7 +20,9 @@ public class CartController {
private CartService cartService; private CartService cartService;
/** /**
* *
* @param cart
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Cart cart) { public Result add(@RequestBody Cart cart) {
@ -29,7 +31,9 @@ public class CartController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +42,9 @@ public class CartController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +53,9 @@ public class CartController {
} }
/** /**
* *
* @param cart
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Cart cart) { public Result updateById(@RequestBody Cart cart) {
@ -56,7 +64,9 @@ public class CartController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -65,7 +75,9 @@ public class CartController {
} }
/** /**
* *
* @param cart
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Cart cart ) { public Result selectAll(Cart cart ) {
@ -74,7 +86,11 @@ public class CartController {
} }
/** /**
* *
* @param cart
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Cart cart, public Result selectPage(Cart cart,
@ -84,4 +100,4 @@ public class CartController {
return Result.success(page); return Result.success(page);
} }
} }

@ -10,8 +10,9 @@ import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
* * CollectController
**/ * 使CollectService
*/
@RestController @RestController
@RequestMapping("/collect") @RequestMapping("/collect")
public class CollectController { public class CollectController {
@ -20,7 +21,10 @@ public class CollectController {
private CollectService collectService; private CollectService collectService;
/** /**
* *
*
* @param collect IDID
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Collect collect) { public Result add(@RequestBody Collect collect) {
@ -29,7 +33,10 @@ public class CollectController {
} }
/** /**
* * ID
*
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +45,10 @@ public class CollectController {
} }
/** /**
* *
*
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +57,10 @@ public class CollectController {
} }
/** /**
* *
*
* @param collect
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Collect collect) { public Result updateById(@RequestBody Collect collect) {
@ -56,7 +69,10 @@ public class CollectController {
} }
/** /**
* ID * ID
*
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -65,7 +81,10 @@ public class CollectController {
} }
/** /**
* *
*
* @param collect ID
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Collect collect ) { public Result selectAll(Collect collect ) {
@ -74,7 +93,12 @@ public class CollectController {
} }
/** /**
* *
*
* @param collect ID
* @param pageNum 1
* @param pageSize 10
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Collect collect, public Result selectPage(Collect collect,
@ -84,4 +108,4 @@ public class CollectController {
return Result.success(page); return Result.success(page);
} }
} }

@ -20,7 +20,10 @@ public class CommentController {
private CommentService commentService; private CommentService commentService;
/** /**
* *
*
* @param comment
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Comment comment) { public Result add(@RequestBody Comment comment) {
@ -29,7 +32,10 @@ public class CommentController {
} }
/** /**
* *
*
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +44,10 @@ public class CommentController {
} }
/** /**
* *
*
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +56,10 @@ public class CommentController {
} }
/** /**
* *
*
* @param comment
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Comment comment) { public Result updateById(@RequestBody Comment comment) {
@ -56,7 +68,10 @@ public class CommentController {
} }
/** /**
* ID * ID
*
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -64,6 +79,12 @@ public class CommentController {
return Result.success(comment); return Result.success(comment);
} }
/**
* ID
*
* @param id ID
* @return
*/
@GetMapping("/selectByGoodsId") @GetMapping("/selectByGoodsId")
public Result selectByGoodsId(@RequestParam Integer id) { public Result selectByGoodsId(@RequestParam Integer id) {
List<Comment> list = commentService.selectByGoodsId(id); List<Comment> list = commentService.selectByGoodsId(id);
@ -71,7 +92,10 @@ public class CommentController {
} }
/** /**
* *
*
* @param comment
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Comment comment ) { public Result selectAll(Comment comment ) {
@ -80,7 +104,12 @@ public class CommentController {
} }
/** /**
* *
*
* @param comment
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Comment comment, public Result selectPage(Comment comment,
@ -90,4 +119,4 @@ public class CommentController {
return Result.success(page); return Result.success(page);
} }
} }

@ -27,14 +27,19 @@ public class FileController {
// 文件上传存储路径 // 文件上传存储路径
private static final String filePath = System.getProperty("user.dir") + "/files/"; private static final String filePath = System.getProperty("user.dir") + "/files/";
// 服务器端口
@Value("${server.port:9090}") @Value("${server.port:9090}")
private String port; private String port;
// 服务器IP
@Value("${ip:localhost}") @Value("${ip:localhost}")
private String ip; private String ip;
/** /**
* *
*
* @param file
* @return
*/ */
@PostMapping("/upload") @PostMapping("/upload")
public Result upload(MultipartFile file) { public Result upload(MultipartFile file) {
@ -59,12 +64,11 @@ public class FileController {
return Result.success(http + flag + "-" + fileName); // http://localhost:9090/files/1697438073596-avatar.png return Result.success(http + flag + "-" + fileName); // http://localhost:9090/files/1697438073596-avatar.png
} }
/** /**
* *
* *
* @param flag * @param flag
* @param response * @param response HTTP
*/ */
@GetMapping("/{flag}") // 1697438073596-avatar.png @GetMapping("/{flag}") // 1697438073596-avatar.png
public void avatarPath(@PathVariable String flag, HttpServletResponse response) { public void avatarPath(@PathVariable String flag, HttpServletResponse response) {
@ -87,7 +91,7 @@ public class FileController {
/** /**
* *
* *
* @param flag * @param flag
*/ */
@DeleteMapping("/{flag}") @DeleteMapping("/{flag}")
public void delFile(@PathVariable String flag) { public void delFile(@PathVariable String flag) {
@ -97,6 +101,9 @@ public class FileController {
/** /**
* wang-editor * wang-editor
*
* @param file
* @return
*/ */
@PostMapping("/wang/upload") @PostMapping("/wang/upload")
public Map<String, Object> wangEditorUpload(MultipartFile file) { public Map<String, Object> wangEditorUpload(MultipartFile file) {

@ -20,7 +20,9 @@ public class GoodsController {
private GoodsService goodsService; private GoodsService goodsService;
/** /**
* *
* @param goods
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Goods goods) { public Result add(@RequestBody Goods goods) {
@ -29,7 +31,9 @@ public class GoodsController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +42,9 @@ public class GoodsController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +53,9 @@ public class GoodsController {
} }
/** /**
* *
* @param goods
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Goods goods) { public Result updateById(@RequestBody Goods goods) {
@ -56,13 +64,20 @@ public class GoodsController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById") @GetMapping("/selectById")
public Result selectById(@RequestParam Integer id) { public Result selectById(@RequestParam Integer id) {
Goods goods = goodsService.selectById(id); Goods goods = goodsService.selectById(id);
return Result.success(goods); return Result.success(goods);
} }
/**
* 15
* @return
*/
@GetMapping("/selectTop15") @GetMapping("/selectTop15")
public Result selectTop15() { public Result selectTop15() {
List<Goods> list = goodsService.selectTop15(); List<Goods> list = goodsService.selectTop15();
@ -70,7 +85,9 @@ public class GoodsController {
} }
/** /**
* *
* @param goods
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Goods goods ) { public Result selectAll(Goods goods ) {
@ -78,18 +95,33 @@ public class GoodsController {
return Result.success(list); return Result.success(list);
} }
/**
* ID
* @param id ID
* @return
*/
@GetMapping("/selectByTypeId") @GetMapping("/selectByTypeId")
public Result selectByTypeId(@RequestParam Integer id) { public Result selectByTypeId(@RequestParam Integer id) {
List<Goods> list = goodsService.selectByTypeId(id); List<Goods> list = goodsService.selectByTypeId(id);
return Result.success(list); return Result.success(list);
} }
/**
*
* @param name
* @return
*/
@GetMapping("/selectByName") @GetMapping("/selectByName")
public Result selectByName(@RequestParam String name) { public Result selectByName(@RequestParam String name) {
List<Goods> list = goodsService.selectByName(name); List<Goods> list = goodsService.selectByName(name);
return Result.success(list); return Result.success(list);
} }
/**
* ID
* @param id ID
* @return
*/
@GetMapping("/selectByBusinessId") @GetMapping("/selectByBusinessId")
public Result selectByBusinessId(@RequestParam Integer id) { public Result selectByBusinessId(@RequestParam Integer id) {
List<Goods> list = goodsService.selectByBusinessId(id); List<Goods> list = goodsService.selectByBusinessId(id);
@ -97,7 +129,11 @@ public class GoodsController {
} }
/** /**
* *
* @param goods
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Goods goods, public Result selectPage(Goods goods,
@ -107,4 +143,4 @@ public class GoodsController {
return Result.success(page); return Result.success(page);
} }
} }

@ -19,7 +19,9 @@ public class NoticeController {
private NoticeService noticeService; private NoticeService noticeService;
/** /**
* *
* @param notice
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Notice notice) { public Result add(@RequestBody Notice notice) {
@ -28,7 +30,9 @@ public class NoticeController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -37,7 +41,9 @@ public class NoticeController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -46,7 +52,9 @@ public class NoticeController {
} }
/** /**
* *
* @param notice
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Notice notice) { public Result updateById(@RequestBody Notice notice) {
@ -55,7 +63,9 @@ public class NoticeController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -64,7 +74,9 @@ public class NoticeController {
} }
/** /**
* *
* @param notice
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Notice notice ) { public Result selectAll(Notice notice ) {
@ -73,7 +85,11 @@ public class NoticeController {
} }
/** /**
* *
* @param notice
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Notice notice, public Result selectPage(Notice notice,
@ -83,4 +99,4 @@ public class NoticeController {
return Result.success(page); return Result.success(page);
} }
} }

@ -20,7 +20,9 @@ public class OrdersController {
private OrdersService ordersService; private OrdersService ordersService;
/** /**
* *
* @param orders
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Orders orders) { public Result add(@RequestBody Orders orders) {
@ -29,7 +31,9 @@ public class OrdersController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +42,9 @@ public class OrdersController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +53,9 @@ public class OrdersController {
} }
/** /**
* *
* @param orders
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Orders orders) { public Result updateById(@RequestBody Orders orders) {
@ -56,7 +64,9 @@ public class OrdersController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -65,7 +75,9 @@ public class OrdersController {
} }
/** /**
* *
* @param orders
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Orders orders ) { public Result selectAll(Orders orders ) {
@ -74,7 +86,11 @@ public class OrdersController {
} }
/** /**
* *
* @param orders
* @param pageNum
* @param pageSize
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Orders orders, public Result selectPage(Orders orders,
@ -84,4 +100,4 @@ public class OrdersController {
return Result.success(page); return Result.success(page);
} }
} }

@ -20,7 +20,9 @@ public class TypeController {
private TypeService typeService; private TypeService typeService;
/** /**
* *
* @param type
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Type type) { public Result add(@RequestBody Type type) {
@ -29,7 +31,9 @@ public class TypeController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -38,7 +42,9 @@ public class TypeController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -47,7 +53,9 @@ public class TypeController {
} }
/** /**
* *
* @param type
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody Type type) { public Result updateById(@RequestBody Type type) {
@ -56,7 +64,9 @@ public class TypeController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -65,7 +75,9 @@ public class TypeController {
} }
/** /**
* *
* @param type
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(Type type ) { public Result selectAll(Type type ) {
@ -74,7 +86,11 @@ public class TypeController {
} }
/** /**
* *
* @param type
* @param pageNum 1
* @param pageSize 10
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(Type type, public Result selectPage(Type type,
@ -84,4 +100,4 @@ public class TypeController {
return Result.success(page); return Result.success(page);
} }
} }

@ -1,9 +1,7 @@
package com.example.controller; package com.example.controller;
import com.example.common.Result; import com.example.common.Result;
import com.example.entity.Business;
import com.example.entity.User; import com.example.entity.User;
import com.example.service.BusinessService;
import com.example.service.UserService; import com.example.service.UserService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -22,7 +20,9 @@ public class UserController {
private UserService userService; private UserService userService;
/** /**
* *
* @param user
* @return
*/ */
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody User user) { public Result add(@RequestBody User user) {
@ -31,7 +31,9 @@ public class UserController {
} }
/** /**
* * ID
* @param id ID
* @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) { public Result deleteById(@PathVariable Integer id) {
@ -40,7 +42,9 @@ public class UserController {
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@DeleteMapping("/delete/batch") @DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) { public Result deleteBatch(@RequestBody List<Integer> ids) {
@ -49,7 +53,9 @@ public class UserController {
} }
/** /**
* *
* @param user
* @return
*/ */
@PutMapping("/update") @PutMapping("/update")
public Result updateById(@RequestBody User user) { public Result updateById(@RequestBody User user) {
@ -58,7 +64,9 @@ public class UserController {
} }
/** /**
* ID * ID
* @param id ID
* @return
*/ */
@GetMapping("/selectById/{id}") @GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) { public Result selectById(@PathVariable Integer id) {
@ -67,7 +75,9 @@ public class UserController {
} }
/** /**
* *
* @param user
* @return
*/ */
@GetMapping("/selectAll") @GetMapping("/selectAll")
public Result selectAll(User user ) { public Result selectAll(User user ) {
@ -76,7 +86,11 @@ public class UserController {
} }
/** /**
* *
* @param user
* @param pageNum 1
* @param pageSize 10
* @return
*/ */
@GetMapping("/selectPage") @GetMapping("/selectPage")
public Result selectPage(User user, public Result selectPage(User user,
@ -86,4 +100,4 @@ public class UserController {
return Result.success(page); return Result.success(page);
} }
} }

@ -26,20 +26,30 @@ public class WebController {
@Resource @Resource
private UserService userService; private UserService userService;
/**
* 访
*
* @return
*/
@GetMapping("/") @GetMapping("/")
public Result hello() { public Result hello() {
return Result.success("访问成功"); return Result.success("访问成功");
} }
/** /**
* *
*
* @param account
* @return
*/ */
@PostMapping("/login") @PostMapping("/login")
public Result login(@RequestBody Account account) { public Result login(@RequestBody Account account) {
// 检查登录参数是否完整
if (ObjectUtil.isEmpty(account.getUsername()) || ObjectUtil.isEmpty(account.getPassword()) if (ObjectUtil.isEmpty(account.getUsername()) || ObjectUtil.isEmpty(account.getPassword())
|| ObjectUtil.isEmpty(account.getRole())) { || ObjectUtil.isEmpty(account.getRole())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR); return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
} }
// 根据用户角色调用相应的登录方法
if (RoleEnum.ADMIN.name().equals(account.getRole())) { if (RoleEnum.ADMIN.name().equals(account.getRole())) {
account = adminService.login(account); account = adminService.login(account);
} }
@ -53,14 +63,19 @@ public class WebController {
} }
/** /**
* *
*
* @param account
* @return
*/ */
@PostMapping("/register") @PostMapping("/register")
public Result register(@RequestBody Account account) { public Result register(@RequestBody Account account) {
// 检查注册参数是否完整
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword()) if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|| ObjectUtil.isEmpty(account.getRole())) { || ObjectUtil.isEmpty(account.getRole())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR); return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
} }
// 根据用户角色调用相应的注册方法
if (RoleEnum.ADMIN.name().equals(account.getRole())) { if (RoleEnum.ADMIN.name().equals(account.getRole())) {
adminService.register(account); adminService.register(account);
} }
@ -74,14 +89,19 @@ public class WebController {
} }
/** /**
* *
*
* @param account
* @return
*/ */
@PutMapping("/updatePassword") @PutMapping("/updatePassword")
public Result updatePassword(@RequestBody Account account) { public Result updatePassword(@RequestBody Account account) {
// 检查修改密码参数是否完整
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword()) if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|| ObjectUtil.isEmpty(account.getNewPassword())) { || ObjectUtil.isEmpty(account.getNewPassword())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR); return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
} }
// 根据用户角色调用相应的修改密码方法
if (RoleEnum.ADMIN.name().equals(account.getRole())) { if (RoleEnum.ADMIN.name().equals(account.getRole())) {
adminService.updatePassword(account); adminService.updatePassword(account);
} }

@ -4,6 +4,7 @@ package com.example.entity;
* *
*/ */
public class Account { public class Account {
// 用户唯一标识
private Integer id; private Integer id;
/** 用户名 */ /** 用户名 */
private String username; private String username;
@ -18,68 +19,133 @@ public class Account {
/** 头像 */ /** 头像 */
private String avatar; private String avatar;
// 用户认证令牌
private String token; private String token;
/**
* ID
* @return ID
*/
public Integer getId() { public Integer getId() {
return id; return id;
} }
/**
* ID
* @param id ID
*/
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
/**
*
* @return
*/
public String getUsername() { public String getUsername() {
return username; return username;
} }
/**
*
* @param username
*/
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
/**
*
* @return
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
*
* @param name
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
*
* @return
*/
public String getPassword() { public String getPassword() {
return password; return password;
} }
/**
*
* @param password
*/
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
/**
*
* @return
*/
public String getRole() { public String getRole() {
return role; return role;
} }
/**
*
* @param role
*/
public void setRole(String role) { public void setRole(String role) {
this.role = role; this.role = role;
} }
/**
*
* @return
*/
public String getNewPassword() { public String getNewPassword() {
return newPassword; return newPassword;
} }
/**
*
* @param newPassword
*/
public void setNewPassword(String newPassword) { public void setNewPassword(String newPassword) {
this.newPassword = newPassword; this.newPassword = newPassword;
} }
/**
*
* @return
*/
public String getAvatar() { public String getAvatar() {
return avatar; return avatar;
} }
/**
*
* @param avatar
*/
public void setAvatar(String avatar) { public void setAvatar(String avatar) {
this.avatar = avatar; this.avatar = avatar;
} }
/**
*
* @return
*/
public String getToken() { public String getToken() {
return token; return token;
} }
/**
*
* @param token
*/
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }

@ -4,7 +4,7 @@ import java.io.Serializable;
/** /**
* *
*/ */
public class Address implements Serializable { public class Address implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -14,46 +14,93 @@ public class Address implements Serializable {
private String useraddress; private String useraddress;
private String phone; private String phone;
/**
* ID
*
* @return ID
*/
public Integer getId() { public Integer getId() {
return id; return id;
} }
/**
* ID
*
* @param id ID
*/
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
/**
* ID
*
* @return ID
*/
public Integer getUserId() { public Integer getUserId() {
return userId; return userId;
} }
/**
* ID
*
* @param userId ID
*/
public void setUserId(Integer userId) { public void setUserId(Integer userId) {
this.userId = userId; this.userId = userId;
} }
/**
*
*
* @return
*/
public String getUsername() { public String getUsername() {
return username; return username;
} }
/**
*
*
* @param username
*/
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
/**
*
*
* @return
*/
public String getUseraddress() { public String getUseraddress() {
return useraddress; return useraddress;
} }
/**
*
*
* @param useraddress
*/
public void setUseraddress(String useraddress) { public void setUseraddress(String useraddress) {
this.useraddress = useraddress; this.useraddress = useraddress;
} }
/**
*
*
* @return
*/
public String getPhone() { public String getPhone() {
return phone; return phone;
} }
/**
*
*
* @param phone
*/
public void setPhone(String phone) { public void setPhone(String phone) {
this.phone = phone; this.phone = phone;
} }
} }

Loading…
Cancel
Save