sql语句
SELECT userid as userid, username as username FROM user WHEREuserid = #userId#;
insert into user values (#userId#,#username#);
update user set username = #username# WHERE userid = #userId#
2. IE(客户端提出请求)——>controller——>model——>controller——>jsp
3. @Autowired 自动注入,不需要声明实例对象
4. controller
package cn.training.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import cn.training.bean.UserBean;import cn.training.service.HelloWorldService;@Controller("HelloWorldController")@RequestMapping("/")public class HelloWorldController { @Autowired HelloWorldService helloWorldService; @RequestMapping(value = "/", method = RequestMethod.GET) public String index(Model model) { return "helloWorld"; } @RequestMapping(value = "/init", method = RequestMethod.POST,params="login") public String initLogin(UserBean userBean, Model model) { UserBean result = helloWorldService.searchUser(userBean); model.addAttribute("userBean", result); return "login"; } @RequestMapping(value = "/init", method = RequestMethod.POST,params="add") public String intinsert(UserBean userBean, Model model) throws Exception { int insert = helloWorldService.insert(userBean); if(insert==1) { UserBean result= new UserBean(); model.addAttribute("userBean", result); model.addAttribute("message", "ok"); return "insertSuccess"; }else { throw new Exception(); } } @RequestMapping(value = "/initupdate", method = RequestMethod.POST,params="update") public String intupdate(UserBean userupdate, Model model) { int update = helloWorldService.updateUser(userupdate); if(update==1) { model.addAttribute("userBean", userupdate); model.addAttribute("message", "ok"); return "login2"; }else { model.addAttribute("message", "false"); return "login2"; } } }
5.javabean
6.${userBean.userId}"获取来自controller的值
7首先在jsp页面-〉controller->model->controller->jsp
实现数据的插入 查询 删除