sql語句java
SELECT userid as userid, username as username FROM user WHEREuserid = #userId#;web
insert into user values (#userId#,#username#);spring
update user set username = #username# WHERE userid = #userId#sql
2. IE(客戶端提出請求)——>controller——>model——>controller——>jspapp
3. @Autowired 自動注入,不須要聲明實例對象jsp
4. controllerui
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.javabeanspa
6.${userBean.userId}"獲取來自controller的值code
7首先在jsp頁面-〉controller->model->controller->jsp對象
實現數據的插入 查詢 刪除