基于Springboot的文件上传下载实现
Springboot上传下载项目
更新中
基于此课程实现
数据库设计
1、用户库表
t_user
create table t_user(
id int(?) primary key,
username varchar,
password varchar
)
t_files
create table t_files(
id int(?) primary key,
oldFileName varchar,
newFileName varchar,
ext varchar,
path varchar,
size varchar,
type varchar,
isImg varchar,
downcounts int(?),
uploadTime varchar
)
2、项目配置
applicatin.properties
spring.application.name=fileupdn
server.port=80
server.servlet.context-path=/
spring.thymeleaf.cache=false
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.prfix-classpath:/templates/
spring.resources.static-locations=classpath:temmplates/,classath:/static/
spring.datasource.type=com.alibaba.druid.pol.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/database?characterEncoding=UTF-8
spring.datasourcce.username=root
spring.datasource.password=root
mybatis.mapper-locations=classpath:/net/zeaz/mapper/*.xml
mybatis.type-aliases-package=net.zeaz.entity
注:为使用mybatis,需在MainApplication中添加注解
@MapperScan("net.zeaz.dao")
3、程序设计及执行
Html -> Controller -> Service (ServiceImpl) -> DAO (Mapper.xml) -> Entity
4、实体
Entity -> User
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User{
private String id;
private String username;
private String password;
}
5、Mapper
<--Login--!>
<select id="login" parameterType="User" resultType="User">
select id,username,password
from t_usser
where username=#{username} and password=#{password}
</select>
6、Service
Service
public interface UserService{
User login(user user);
}
ServiceImpl
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserDAO userDAO;
@Override
public User login(User user){
return userDAO.login(user);
}
}
7、Controller
@Controller
#RequestMapper("User")
public class UserController{
@Autowired
private UserService userService;
/*Login*/
@PostMapping("login")
public String login(User user,HttpSession session){
User user = userService.login(user);
if(user != null){
session.setAttribute("user",user);
return "redirect:file/showAll";
}else{
return "redirect:/login.html";
}
}
}

浙公网安备 33010602011771号