3/4
-
文件的配置问题(主要针对mybatis和mybatisplus)【两个都要写】
-
#mybatis配置 mybatis: typeAliasesPackage: com.example.mall1.entity mapperLocations: classpath:mapper/*.xml configuration: map-underscore-to-camel-case: true mybatis-plus: # 搜索指定包别名 typeAliasesPackage: com.example.* # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath:mapper/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml
-
-
数据库的配置需要依赖的添加
datasource: username: root password: root url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver
-
@GetMappering和@PostMappering的区别
- GetMappering地址栏有明确信息;PostMappering地址栏信息隐藏
- 大多数情况用PostMappering
-
测试用swagger,应该是版本不兼容的问题,死活用不了,最后使用了Apifox
3/5
-
上传图片/文件的具体操作
写在配置文件中 #图片存储路径 image: path: /E:/picture/
serviceImpl层 @Autowired private PictureMapper pictureMapper; @Value("${image.path}") private String imagePath; /** * 上传图片【到数据库】【插入操作】 * @param * @return */ @Override public String insertPicture(MultipartFile file, HttpServletRequest httpServletRequest) throws IOException { //将获取的文件转换为一个字节流 byte[] fileBytes=file.getBytes(); //对图片进行md5加密[将字节流转换为16进制] String md5=null; md5= DigestUtils.md5DigestAsHex(fileBytes); //获取文件的名字,后缀名,路径 String fileName= file.getOriginalFilename(); String lastName = fileName.substring(1+fileName.indexOf(".")); String path = imagePath + md5 +"."+lastName;//将路径设置为新的字符串 //如果文件dest没有目录,创建一个 File dest = new File(path); if(!dest.getParentFile().exists()){ dest.getParentFile().mkdirs(); } file.transferTo(dest);//把文件存放在dest中 //把文件/图片上传到数据库[返回的是id] Picture picture = new Picture(); picture.setPictureName(fileName); picture.setPictureMd5(md5); picture.setPictureSuffix(lastName); picture.setPictureSize(file.getSize()); picture.setPictureType(file.getContentType()); picture.setPicturePath(imagePath); // this.save(picture); pictureMapper.insert(picture); System.out.println(picture.getId()); return String.valueOf(picture.getId()); }