1、创建项目project,然后选择Spring initializr,点击下一步
2、按图示进行勾选,点击下一步,给项目起个名字,点击确定。
项目结构
3.配置application.properties
server.port=8081
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations= classpath:mapper
@GetMapping("/getOne")
public String getOne(Integer id){
FunUsers usr = iFunUsers.selectByPrimaryKey(id);
return usr.toString();
}
@RequestMapping(value = "delete/{userId}")
public ModelAndView delete(@PathVariable Integer userId) {
iFunUsers.deleteByPrimaryKey(userId);
ModelAndView mav = new ModelAndView("redirect:/funUser/all");
return mav;
}
@RequestMapping("addUser")
public ModelAndView AddUser(FunUsers funUsers) {
funUsers.setAddTime(new Date());
iFunUsers.insertSelective(funUsers);
ModelAndView mav = new ModelAndView("redirect:/funUser/all");
return mav;
}
@RequestMapping("add")
public ModelAndView Add1() {
return new ModelAndView("/user/add");
}
@RequestMapping("edit")
public String edit(Integer id ,Model model){
FunUsers userInfo = iFunUsers.selectByPrimaryKey(id);
model.addAttribute("userInfo",userInfo);
return "user/edit";
}
@RequestMapping("updateUsers")
public ModelAndView updateUser(FunUsers users) {
users.setUpdateTime(new Date());
iFunUsers.updateByPrimaryKey(users);
ModelAndView mav = new ModelAndView("redirect:/funUser/all");
return mav;
}
}
5.FunUsers
public class FunUsers implements Serializable {
private Integer id;
private String username;
private String usernumber;
private String number;
private String maogai;
private String shuzhi;
private String modian;
private String yinyu;
private String web;
private String riyu;
private String shuju;
private String wuli;
private String dashuju;
private String java;
private String bujige;
private String pingjun;
private String zongfen;
private String zongxuefen;
private String pjxf;
private String pjjd;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date addTime;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateTime;
private Boolean deleted;
private String keywords;
}
6.User:
public class User{
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
7.UserService:
public interface UserService {
List queryList(User user);
}
8.FunUsersMapper:
public interface FunUsersMapper {
int deleteByPrimaryKey(Integer id);
int insertSelective(FunUsers record);
FunUsers selectByPrimaryKey(Integer id);
int updateByPrimaryKey(FunUsers users);
List getAll();
List selectKeyWords(FunUsers keywords);
}
9.FunUsersImpl:
public class FunUsersImpl implements IFunUsersService {
@Autowired
private FunUsersMapper funUsersMapper;
@Override
public int deleteByPrimaryKey(Integer id) {
return funUsersMapper.deleteByPrimaryKey(id);
}
@Override
public int insertSelective(FunUsers record) {
return funUsersMapper.insertSelective(record);
}
@Override
public FunUsers selectByPrimaryKey(Integer id) {
return funUsersMapper.selectByPrimaryKey(id);
}
@Override
public int updateByPrimaryKey(FunUsers users) {
return funUsersMapper.updateByPrimaryKey(users);
}
@Override
public List getAll() {
return funUsersMapper.getAll();
}
@Override
public List selectKeyWords(FunUsers keywords) {
return funUsersMapper.selectKeyWords(keywords);
}
}
10.IFunUsersService:
public interface IFunUsersService {
int deleteByPrimaryKey(Integer id);
int insertSelective(FunUsers record);
FunUsers selectByPrimaryKey(Integer id);
int updateByPrimaryKey(FunUsers users);
List getAll();
List selectKeyWords(FunUsers keywords);
}
11.add.html
首页
新增用户信息
12.allUser.html
首页
13.edit.html
首页
修改用户信息
数据库:
运行结果:
总结:这次实验运用到了spring boot和mybatis以及MySQL数据库来搭建这个web项目,用mybatis来对数据库进行访问可以说是很方便了,mybatis的自动生成工具也生成对应数据库文件的映射,而MySQL的数据直接导入得到的表格即可,只是界面不太美观。



