美文网首页
Controller, Service,Dao,xml 编写

Controller, Service,Dao,xml 编写

作者: 如果大雨落下 | 来源:发表于2022-05-13 00:02 被阅读0次

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!

相关文章

网友评论

      本文标题:Controller, Service,Dao,xml 编写

      本文链接:https://www.haomeiwen.com/subject/odaeurtx.html