zoukankan      html  css  js  c++  java
  • springboot mybatis搭建

    非常easy直接写,没有搭建成分

    1、目录

    2、

    @RestController
    public class UserController {
        @RequestMapping("/hello")
        public String index() {
            return "Hello World";
        }
    
        @Autowired
        UserService userService;
    
        @RequestMapping(value = "/list", method = RequestMethod.GET)
        public List<User> getAccounts() {
            return userService.getUserList();
        }
    }

    3、

    @Mapper
    public interface UserMapper {
    
        @Select("SELECT * FROM tb_user WHERE id = #{id}")
        User getUserById(Integer id);
    
        @Select("SELECT * FROM tb_user")
        public List<User> getUserList();
    
    }

    4、

    @Service
    public class UserService {
        @Autowired
        private UserMapper userMapper;
    
        public List<User> getUserList() {
            return userMapper.getUserList();
        }
    }

    6、

    public class User {
        private int id;
        private String username;
        private int age;
    
        public User(int id, String username, int age) {
            this.id = id;
            this.username = username;
            this.age = age;
        }
        public User(Long id, String username, Long age) {
            this.id = Math.toIntExact(id);
            this.username = username;
            this.age = Math.toIntExact(age);
        }
      //不知道为啥报错,就按照提示来呗
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    }

    7、

    application.properties

    spring.datasource.url=jdbc:mysql://localhost:3306/test
    spring.datasource.username=root
    spring.datasource.password=123456
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  • 相关阅读:
    Anaconda + Djongo + spyder 网站开发 (三)
    Anaconda + Djongo + spyder 网站开发 (二)
    Anaconda + Djongo + spyder 网站开发 (一)
    实验室网盘链接方式
    R 缓存画图代码,之后再总结
    换源的重要性!!!!
    latex 调整页边距
    Latex 字体设置
    嵌套交叉验证
    FDR及Benjamini-Hochberg方法
  • 原文地址:https://www.cnblogs.com/cnchengv/p/9884142.html
Copyright © 2011-2022 走看看