1、创建项目project,然后选择Spring initializr,点击下一步
2、按图示进行勾选,点击下一步,给项目起个名字,点击确定。
项目结构
3.配置application.properties
server.port=8081spring.datasource.url=jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTCspring.datasource.username=rootspring.datasource.password=123456spring.datasource.driver-class-name=com.mysql.cj.jdbc.Drivermybatis.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
8.FunUsersMapper:
public interface FunUsersMapper { int deleteByPrimaryKey(Integer id); int insertSelective(FunUsers record); FunUsers selectByPrimaryKey(Integer id); int updateByPrimaryKey(FunUsers users); List
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
10.IFunUsersService:
public interface IFunUsersService { int deleteByPrimaryKey(Integer id); int insertSelective(FunUsers record); FunUsers selectByPrimaryKey(Integer id); int updateByPrimaryKey(FunUsers users); List
11.add.html
12.allUser.html
姓名 学号 课程门数 毛概学分 数值学分 模电学分 英语学分 WEB学分 日语学分 数据结构学分 物理学分 大数据学分 JAVA学分 不及格门数 平均分 总分 总学分 平均学分绩 平均绩点 添加时间 修改时间 操作
13.edit.html
数据库:
运行结果:
总结:这次实验运用到了spring boot和mybatis以及MySQL数据库来搭建这个web项目,用mybatis来对数据库进行访问可以说是很方便了,mybatis的自动生成工具也生成对应数据库文件的映射,而MySQL的数据直接导入得到的表格即可,只是界面不太美观。