电商后台管理系统(基于SSM + Vue + Restful + jquery + axios)
创始人
2024-01-29 05:03:43
0

1.项目架构

2.config配置

JdbcConfig

public class JdbcConfig {@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String username;@Value("${jdbc.password}")private String password;@Beanpublic DataSource dataSource(){DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName(driver);dataSource.setUrl(url);dataSource.setUsername(username);dataSource.setPassword(password);return dataSource;}@Beanpublic PlatformTransactionManager transactionManager(DataSource dataSource){DataSourceTransactionManager ds = new DataSourceTransactionManager(dataSource);return ds;}}

 MyBatisConfig

public class MyBatisConfig {@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();factoryBean.setTypeAliasesPackage("cn.itaxu.domain");factoryBean.setDataSource(dataSource);return factoryBean;}@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc = new MapperScannerConfigurer();msc.setBasePackage("cn.itaxu.dao");return msc;}}

ServletConfig

public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {// 加载spring配置@Overrideprotected Class[] getRootConfigClasses() {return new Class[]{SpringConfig.class};}// 加载springMVC配置@Overrideprotected Class[] getServletConfigClasses() {return new Class[]{SpringMvcConfig.class};}// 设置哪些方法归属springMVC处理@Overrideprotected String[] getServletMappings() {return new String[]{"/"};}// 处理POST请求中文乱码问题@Overrideprotected Filter[] getServletFilters() {CharacterEncodingFilter filter = new CharacterEncodingFilter("UTF-8");return new Filter[]{filter};}}

SpringConfig

@Configuration
@ComponentScan("cn.itaxu.service")
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MyBatisConfig.class})
@EnableTransactionManagement
public class SpringConfig {
}

SpringMvcConfig

@Configuration
@ComponentScan({"cn.itaxu.controller","cn.itaxu.config"})
@EnableWebMvc
public class SpringMvcConfig {
}

SpringMvcSupport

@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {@Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");registry.addResourceHandler("/img/**").addResourceLocations("/img/");}
}

3.controller控制

BrandController

@RestController
@RequestMapping("/brands")
public class BrandController {@Autowiredprivate BrandService brandService;@PostMappingpublic Result save(@RequestBody Brand brand){boolean flag = brandService.save(brand);return new Result(flag ? Code.SAVE_OK:Code.SAVE_ERR,flag);}@DeleteMapping("/{id}")public Result deleteById(@PathVariable Integer id){boolean flag = brandService.deleteById(id);return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);}@DeleteMappingpublic Result deleteMultiply(@RequestBody int[] ids){boolean flag = brandService.deleteMultiply(ids);return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);}@PutMappingpublic Result update(@RequestBody Brand brand){System.out.println(brand);boolean flag = brandService.update(brand);return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);}@GetMapping("/{id}")public Result getById(@PathVariable Integer id){Brand brand = brandService.getById(id);Integer code =brand != null ? Code.GET_OK:Code.GET_ERR;String msg = brand != null ? "success":"fail";return new Result(code,brand,msg);}@GetMappingpublic Result getAll(){List brandList = brandService.getAll();Integer code = brandList != null ? Code.GET_OK:Code.GET_ERR;String msg = brandList != null ? "success":"fail";return new Result(code,brandList,msg);}@PostMapping("/{currentPage}/{pageSize}")public Result selectByPageAndCondition(@PathVariable int currentPage,@PathVariable int pageSize,@RequestBody Brand brand) {PageBean pageBean = brandService.selectByPageAndCondition(currentPage, pageSize, brand);Integer code = pageBean != null ? Code.GET_OK:Code.GET_ERR;String msg = pageBean != null ? "success":"fail";return new Result(code,pageBean,msg);}
}

Code 响应状态码

public class Code {public static final Integer SAVE_OK = 20011;public static final Integer DELETE_OK = 20021;public static final Integer UPDATE_OK = 20031;public static final Integer GET_OK = 20041;public static final Integer SAVE_ERR = 20010;public static final Integer DELETE_ERR = 20020;public static final Integer UPDATE_ERR = 20030;public static final Integer GET_ERR = 20040;public static final Integer SYSTEM_ERR = 50001;public static final Integer SYSTEM_TIMEOUT_ERR = 50002;public static final Integer SYSTEM_UNKNOW_ERR = 59999;public static final Integer BUSINESS_ERR = 60002;
}
ProjectExceptionAdvice 项目异常通知
@RestControllerAdvice
public class ProjectExceptionAdvice {@ExceptionHandler(SystemException.class)public Result doSystemException(SystemException ex){// 记录日志// 发送消息给运维// 发送消息给开发人员,ex对象发送给开发人员return new Result(ex.getCode(),"null","系统异常");}@ExceptionHandler(BusinessException.class)public Result doBusinessException(BusinessException ex){return new Result(ex.getCode(),"null","业务异常");}@ExceptionHandler(Exception.class)public Result doException(Exception ex){// 记录日志// 发送消息给运维// 发送消息给开发人员,ex对象发送给开发人员return new Result(Code.SYSTEM_UNKNOW_ERR,"null","系统繁忙,请稍后再试!");}
}

Result 统一格式数据

public class Result {private Object data;private Integer code;private String  msg;public Result() {}public Result(Integer code,Object data) {this.data = data;this.code = code;}public Result(Integer code, Object data, String msg) {this.data = data;this.code = code;this.msg = msg;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}}

4.exception 细化异常

BusinessException 业务异常

public class BusinessException extends RuntimeException{private Integer code;public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public BusinessException(Integer code, String message) {super(message);this.code = code;}public BusinessException(Integer code, String message, Throwable cause) {super(message, cause);this.code = code;}}
SystemException 系统异常
public class SystemException extends RuntimeException{private Integer code;public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public SystemException(Integer code, String message) {super(message);this.code = code;}public SystemException(Integer code, String message, Throwable cause) {super(message, cause);this.code = code;}}

5.service

BrandService接口

@Transactional
public interface BrandService {/*** 添加数据* @param brand* @return*/public boolean save(Brand brand);/*** 根据id删除* @param id* @return*/public boolean deleteById(Integer id);/*** 根据ids批量删除* @param ids* @return*/public boolean deleteMultiply(@Param("ids") int[] ids);/*** 修改数据* @param brand* @return*/public boolean update(Brand brand);/*** 查询单条* @param id* @return*/public Brand getById(Integer id);/*** 查询所有* @return*/public List getAll();/*** 分页查询* @param currentPage* @param pageSize* @return*/PageBean selectByPage(int currentPage, int pageSize);/*** 分页条件查询* @param currentPage* @param pageSize* @param brand* @return*/PageBean selectByPageAndCondition(int currentPage, int pageSize, Brand brand);
}

BrandServiceImpl

@Service
public class BrandServiceImpl implements BrandService {@Autowiredprivate BrandDao brandDao;@Overridepublic boolean save(Brand brand) {return brandDao.save(brand) > 0;}@Overridepublic boolean deleteById(Integer id) {return brandDao.deleteById(id) > 0;}@Overridepublic boolean deleteMultiply(int[] ids) {return brandDao.deleteMultiply(ids) > 0;}@Overridepublic boolean update(Brand brand) {return brandDao.update(brand) > 0;}@Overridepublic Brand getById(Integer id) {return brandDao.getById(id);}@Overridepublic List getAll() {return brandDao.getAll();}@Overridepublic PageBean selectByPage(int currentPage, int pageSize) {int begin = (currentPage-1) * pageSize;int size = pageSize;List rows = brandDao.selectByPage(begin, size);int totalCount = brandDao.selectTotalCount();PageBean pageBean = new PageBean();pageBean.setRows(rows);pageBean.setTotalCount(totalCount);return pageBean;}@Overridepublic PageBean selectByPageAndCondition(int currentPage, int pageSize, Brand brand) {int begin = (currentPage-1) * pageSize;int size = pageSize;// 处理模糊查询String brandName = brand.getBrandName();if (brandName!=null&&brandName.length()>0){brand.setBrandName("%"+brandName+"%");}String companyName = brand.getCompanyName();if (companyName!=null&&companyName.length()>0){brand.setCompanyName("%"+companyName+"%");}// 查询当前页数据List brandList = brandDao.selectByPageAndCondition(begin, size, brand);// 查询当前页总记录条数int totalCount = brandDao.selectTotalCountByCondition(brand);// 封装PageBeanPageBean pageBean = new PageBean<>(brandList,totalCount);return pageBean;}}

6.前端代码

处理中心后台品牌模型消息中心订单管理查询批量删除新增提交取消提交取消

产品列表

js







7.页面展示

 

 

 

结语:

希望这些能够帮助到你的学习!!! 如果有需要源码的私信我

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
一帆风顺二龙腾飞三阳开泰祝福语... 本篇文章极速百科给大家谈谈一帆风顺二龙腾飞三阳开泰祝福语,以及一帆风顺二龙腾飞三阳开泰祝福语结婚对应...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...