springboot从零开始[1] gradle+mybatis注解
来源:互联网 发布:debian mysql 编辑:程序博客网 时间:2024/06/07 14:05
springboot从零开始[1] gradle+mybatis注解
从来都没接触过过,各方面消息都说springboot是个好东西,那就开始学吧,好东西就是要get!
毕竟小白,从零开始学习,一步步慢慢来吧,然后尽量做到具体。
先来看看全部的结构,是很简单的结构,因为入门嘛
下面开始动手了!
- 当然是建表了
CREATE TABLE users ( id VARCHAR (36) NOT NULL PRIMARY KEY, user_name VARCHAR (36) NOT NULL, PASSWORD VARCHAR (100) NOT NULL, create_date DATETIME NULL, create_by VARCHAR (36) NULL) ;
- application.properties,这里设置了数据库连接地址及日志级别
spring.datasource.url=jdbc:mysql://localhost:3306/castlespring.datasource.username=rootspring.datasource.password=1234spring.datasource.driverClassName=com.mysql.jdbc.Drivermybatis.config-location=classpath:mybatis-config.xmllogging.level.root=INFOlogging.level.sample.mybatis.mapper=DEBUG
上面的application.properties中有个mybatis.config-location,是为mybatis做更细致的设置
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <settings> <!-- 使用驼峰命名法转换字段。 --> <setting name="mapUnderscoreToCamelCase" value="true"/> </settings></configuration>
比如必要的驼峰转换~
- 码代码了
实体User
package top.aircastle.springboot.comment.domin;/** * Created by Castle on 2017/8/9. */public class User { private String id; private String userName; private String password; private String createDate; private String createBy; public String getId() { return id; } public void setId(String 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; } public String getCreateDate() { return createDate; } public void setCreateDate(String createDate) { this.createDate = createDate; } public String getCreateBy() { return createBy; } public void setCreateBy(String createBy) { this.createBy = createBy; }}
Mapper文件UserMapper
package top.aircastle.springboot.comment.mapper;import org.apache.ibatis.annotations.*;import top.aircastle.springboot.comment.domin.User;import java.util.List;/** * Created by Castle on 2017/8/9. */@Mapperpublic interface UserMapper { @Select(value = {"SELECT * FROM user WHERE user_name = #{userName}"}) List<User> getUserByUserName(String userName); @Select(value = { "SELECT * FROM user" }) List<User> listAllUser(); @Select(value = "INSERT INTO USER (id,user_name,PASSWORD,create_date,create_by) VALUES (REPLACE(UUID(), '-', ''),'test0','1234',NOW(),'test')") int addUser(User user);}
控制器UserController
package top.aircastle.springboot.comment.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;import top.aircastle.springboot.comment.domin.User;import top.aircastle.springboot.comment.mapper.UserMapper;import java.util.List;/** * Created by Castle on 2017/8/9. */@RestController@RequestMapping("/user")public class UserController { @Autowired UserMapper userMapper; @RequestMapping(value = "getUserByUserName", method = RequestMethod.POST) public List<User> getUserByUserName(@RequestParam(name = "userName", required = false) String userName) { List<User> data = userMapper.getUserByUserName(userName); return data; } @RequestMapping(value = "listAllUser", method = RequestMethod.POST) List<User> listAllUser() { List<User> data = userMapper.listAllUser(); return data; } @RequestMapping(value = "addUser", method = RequestMethod.POST) int listAllUser(@RequestBody User user) { int data = userMapper.addUser(user); return data; }}
- SampleApplication启动类
package top.aircastle.springboot.comment;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SampleApplication { public static void main(String[] args) { SpringApplication.run(SampleApplication.class, args); }}
现在就可以开始运行了,下面我贴张自测的截图吧
阅读全文
0 0
- springboot从零开始[1] gradle+mybatis注解
- springboot从零开始[2] gradle+mybatis xml
- SpringBoot MyBatis注解
- MyBatis springboot gradle 开发配置
- springboot-gradle + mybatis-generator-plugin
- Springboot集成mybatis注解方式
- springboot整合mybatis 注解实现
- springboot之整合mybatis-annotation(注解方式)
- Springboot集成Mybatis之注解篇
- springboot中使用Mybatis注解配置详解
- 5.springboot整合mybatis(注解方式)
- springboot 注解方式整合mybatis (mysql数据库)
- 从零开始学 SpringBoot (1)
- SpringBoot入门-16(springboot集成mybatis注解形式)
- 从零开始springBoot
- IDEA下创建Springboot,thymeleaf,Mybatis,Postgresql,Gradle项目
- springboot+mybatis+gradle在idea和oracle使用
- Gradle构建SpringBoot+Mybatis集成分页插件PageHelper
- POJ
- 新手玩CSS中的一些黑科技
- python_lintcode_简单题_8旋转字符_420报数_197排列序号
- C++知识总结(19)
- KS文件
- springboot从零开始[1] gradle+mybatis注解
- jquery(js) each跳出循环,跳过循环
- mybatis的mapper映射器引入映射文件
- 300W数据集测试MTCNN的landmark效果代码
- 数学建模 模拟退火入门介绍
- 在deepin(linux)下安装matlab2017a
- 一份KS文件
- Java内部类的概述
- C++知识总结(20)