dsc 7 months ago
parent c16be78eee
commit c7f707af80

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save