1. 创建model
public class Note {
private int id;
private String user_id;
private String note_id;
private String title;
private String content;
private String rich_content;
private String images;
private long create_time;
private long update_time;
private String annex;
private String option_id;
private int type;
}
public class User {
private int id;
private String user_id;
private String password;
private String username;
private String avatar;
private int gender;
private int role;
private long register_time;
private String mail;
}
public class Friend {
private int id;
private String f_id;
private String name;
private String description;
private String url;
private String icon;
}
public class Comment {
private int id;
private String user_id;
private String note_id;
private String c_id;
private String ip;
private String content;
private long create_time;
private String reply_id;
private String status;
private int level;
}
public class Option {
private int id;
private String option_id;
private String name;
private String description;
}
2. 创建controller,service,serviceimpl,dao,dao.xml
1.jpg
3. 开启mybatis扫描
@SpringBootApplication
@MapperScan("com.dtyy.dao") //扫描包
public class LearnSpringBootApplication {
//给到加mapper注解
@Mapper
@Component
public interface CommentDao {
4.mybatis 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="com.dtyy.dao.UserDao">
<select id="getAllUsers" resultType="User">
SELECT * from t_users
</select>
</mapper>
5. controller 接口调试
@RestController
public class UserController {
private UserService userService;
@Autowired
public void setUserService(UserService userService) {
this.userService = userService;
}
@GetMapping("/allUsers")
public List<User> allUsers(){
try {
List<User> users = userService.getAllUsers();
return users;
}catch (Exception e){
}
return null;
}
}
ok!
网友评论