1.数据库建立ssm库,建立user表
2.user实体类
public class User {
private int id;
private String name;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
3.UserDao
public interface UserDao {
public User queryUserById(int id);
}
4.UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.example.ssm.dao.UserDao">
<select id="queryUserById" parameterType="int" resultType="org.example.ssm.vo.User">
select *
from user
where id=#{id}
</select>
</mapper>
5.UserService
@Service
public class UserService {
@Autowired
private UserDao userDao;
public User queryUserById(int id){
return userDao.queryUserById(id);
}
}
6.UserController
@Controller
public class UserController {
@Resource
private UserService userService;
@RequestMapping("user")
public String user(int id, Model model){
User user=userService.queryUserById(id);
model.addAttribute("user",user);
return "hello";
}
}
标签:String,int,环境,private,id,user,测试,public
From: https://www.cnblogs.com/lwx11111/p/16805703.html