SSM框架实现JDBC的增删改查
实习第四天
今天的实习中,老师对如何构建SSM框架与封装的代码部分进行了讲解,现在做一个小结。
IDEA中项目组成
外框架:
java包
java包会设置成sources root,设定为源代码目录;resources包会设置成resources root,来作为应用程序中的资源文件的包。这两种设置都是通过右键包–>Mark Directory as–>sources root/resources root实现的。
resources包
webapp包
各包中各个文件的作用
1. java包
UserInfo.class:
对数据库中的三个变量id、username、password进行定义,加上getter、setter方法封装,获得/设置这三个变量的值,以及toString()来返回这三个变量的值。
UserController.class:
package com.zhongruan.controller;
import com.zhongruan.bean.Userinfo;
import com.zhongruan.service.IUserService;
import com.zhongruan.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.Model;
import javax.management.modelmbean.ModelMBean;
import javax.xml.registry.infomodel.User;
import java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("/findAll.do")
public ModelAndView findALL(){
List<Userinfo>