Archetype Created Web Application/index.jspcontextConfigLocationclasspath:applicationContext.xmlorg.springframework.web.context.ContextLoaderListenerencodingFilterorg.springframework.web.filter.CharacterEncodingFiltertrueencodingUTF-8encodingFilter/*SpringMVCorg.springframework.web.servlet.DispatcherServletcontextConfigLocationclasspath:applicationContext.xml1trueSpringMVC/
这是我的目录结构
User.java
package com.ssm.dto;
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password == null ? null : password.trim();
}
}
IUserService.java
package com.ssm.service;
import java.util.List;
import com.ssm.dto.User;
public interface IUserService {
public User getUserById(int userId);
public void insertUser(User user);
public void addUser(User user);
public List getAllUser();
}
IUserDao.java
package com.ssm.dao;
import java.util.List;
import java.util.Map;
import com.ssm.dto.User;
public interface IUserDao {
public User queryByPrimaryKey(Integer id);
public List queryUserByBatch(Map params);
public void insertUser(User user);
public void insertUserByBatch(List list);
public void deleteByPrimaryKey(Integer id);
public void delteUserByBatch(Map params);
public void updateByPrimaryKey(Integer id);
public List getAllUser();
}
UserMapper.xml
id, username, password
insert into admin_user
id,
username,
password,
#{id,jdbcType=INTEGER},
#{username,jdbcType=VARCHAR},
#{password,jdbcType=VARCHAR},
insert into admin_user
(ID,
NAME,
PASSWORD,
)
select A.* from
(
select
#{user.id,jdbcType=INTEGER},
#{user.name,jdbcType=VARCHAR},
#{user.password,jdbcType=VARCHAR},
from dual
) A
delete from admin_user
where id = #{id,jdbcType=INTEGER}
delete from admin_user
where id IN
#{ids,jdbcType=DECIMAL}
update admin_user
name = #{name,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
where id = #{id,jdbcType=INTEGER}
UserController.java
package com.ssm.controller;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ssm.dto.User;
import com.ssm.service.IUserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private IUserService userService;
@RequestMapping("/userList")
public String userList(HttpServletRequest request,Model model){
List uList = userService.getAllUser();
model.addAttribute("uList", uList);
return "userList";
}
@RequestMapping("/showUser")
public String showUser(HttpServletRequest request,Model model){
int userId = Integer.parseInt(request.getParameter("id"));
User user = userService.getUserById(userId);
model.addAttribute("user", user);
return "showUser";
}
@RequestMapping("/addUserUI")
public String addUserUI(){
return "addUser";
}
@RequestMapping("/addUser")
public String addUser(HttpServletRequest request,Model model){
User user = new User();
user.setUsername(String.valueOf(request.getParameter("name")));
user.setPassword(String.valueOf(request.getParameter("password")));
userService.addUser(user);
return "redirect:/user/userList";
}
}
快速高效用:SET SQL_SAFE_UPDATES = 0;下面的就不要看了!
今日用MySQL Workbench进行数据库的管理更新时,执行一个更新的语句碰到以下错误提示:
Error Code: 1175
You are using safe update mode and you tried to update a table without a WHERE that
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:You may assume that nums1 has enough space (size that is