技术标签: java
创建数据库及数据表:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`springbootdb` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `springbootdb`;
/*Table structure for table `user` */
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`username` varchar(16) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2,创建User.java
package com.spb.SpringBootDemo.vo;
public class User {
private String id;
private String username;
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;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
3, 在pom.xml中加入:
<properties>
<mybatis-spring-boot>1.2.0</mybatis-spring-boot>
<mysql-connector>5.1.39</mysql-connector>
</properties>
<!-- Spring Boot Mybatis 依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot}</version>
</dependency>
<!-- MySQL 连接驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector}</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
4, 在resource下加入application.properties文件,mysql和mybatis可以根据自己的地址配置。
spring.datasource.url=jdbc:mysql://localhost:3306/springbootdb?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
mybatis.typeAliasesPackage=org.spring.springboot.domain
mybatis.mapperLocations=classpath:mapper/*.xml
1
2
3
4
5
6
7
8
9
5,新增UserDao,并在resources下面创建mapper目录,在下面创建UserMapper.xml
package com.spb.SpringBootDemo.dao;
import java.util.List;
import com.spb.SpringBootDemo.vo.User;
/**
*
* @author Administrator
*
*/
public interface UserDao {
/**
* 新增用户
* @param user
*/
void createUser(User user);
/**
* 查询用户列表
* @return
*/
List<User> findAllUser();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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.spb.SpringBootDemo.dao.UserDao">
<resultMap id="BaseResultMap" type="com.spb.SpringBootDemo.vo.User">
<result column="id" property="id" />
<result column="username" property="username" />
</resultMap>
<parameterMap id="User" type="com.spb.SpringBootDemo.vo.User"/>
<sql id="Base_Column_List">
id, username
</sql>
<select id="findAllUser" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from user
</select>
<insert id="createUser" parameterMap="User" useGeneratedKeys="true" keyProperty="id">
insert into
user(id,username)
values
(#{id},#{username})
</insert>
</mapper>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
6,最后增加service和实现controller,这里service省略。
package com.spb.SpringBootDemo.rest;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spb.SpringBootDemo.service.IUserService;
import com.spb.SpringBootDemo.vo.User;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService service;
@RequestMapping("/userList")
public List<User> getUserList(){
return service.findAllUser();
}
@RequestMapping("/add")
public String addUser(@RequestBody User user){
if(user!=null){
service.createUser(user);
return "success";
}else{
return "error";
}
}
}
app.java中加入注解@MapperScan("com.spb.SpringBootDemo.dao")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
测试:
运行项目
用postman测试
源码:http://download.csdn.net/download/u012343297/10163177
CSS:解决高度塌陷的三种方什么是高度塌陷: 父盒子自动适应子盒子,子盒子float之后,父盒子的高度变为0。解决高度塌陷的三种方式:w3c组织推荐的方式:多加一个子盒子(只是用来解决高度塌陷,并不会破坏布局),class=clearfix .clearfix{ clear: both; }给父盒子的样式加上:overflow: hidden;...
第一步:设置brewbrew tap homebrew/dupesbrew tap homebrew/versionsbrew tap homebrew/homebrew-php第二部:安装php7brew install php70 (建议使用下面的方式)brew install php70 --with-apxs2 --with-apache --with-gmp --with-imap ...
首先我们看看最基本最简单的try-catch写法并对其进行分析。public static void main(String[] args) { System.out.println(show());} static int show(){ try { System.out.println("try"); return 1; } catch (Exception ...
华为C/C++笔试题(附答案) 关键词:C语言面试题 C++面试题 华为面试题 本文地址:http://www.teecool.com/post/2007081104.html内容正文: 1.写出判断ABCD四个表达式的是否正确, 若正确, 写出经过表达式中 a的值(3分)int a = 4;(A)a += (a++); (B) a += (++a) ;(C) (a++) += a;(D)
报错信息提示:E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED原因分析:GPU显存设置有问题,需要设置为仅在需要时申请显存。import tensorflow as tfconfig = tf.compat.v1.Conf...
yolov5测试单张图片,返回一个列表[类别,置信度,x,y,w,h]from numpy import randomimport torchfrom models.experimental import attempt_loadfrom utils.datasets import LoadStreams, LoadImagesfrom utils.general import ( check_img_size, non_max_suppression, apply_classifier
本来打算把这篇文章的题目叫做使用语法分析进行面对对象的设计,但是写在这里的语法分析很容易使人(尤其是程序员)想到一种编程语言的语法,而不是我在这里所说得我们日常生活中所使用的语言中的语法(但是为了方便起见,我在后面仍使用语法分析作为这种面对对象设计方法的名称)。也许使用使用语法分析的方法进行面向对象的设计并不是一个新的概念,但是在我收集资料的过程中只在浙大的教学网站上发现了关于这一方法的一些资
初次接触对图形操作的问题,实在不会了,请教。问题:对通过多线程产生的各个球分别进行操作,判断再次点击处是否在图形上,这个判断整不了,下面是代码,由于长度限制的问题省略了部...初次接触对图形操作的问题,实在不会了,请教。问题:对通过多线程产生的各个球分别进行操作,判断再次点击处是否在图形上,这个判断整不了,下面是代码,由于长度限制的问题省略了部分系统自动添加代码。package mypaint;i...
案例一使用读写锁实现线程同步读写锁与互斥量类似,但读写锁允许更高的并行性。其特性为:写独占,读共享。读写锁特性:(1)读写锁是“写模式加锁”时,解锁前,所有对该锁加锁的线程都会被阻塞。(2)读写锁是“读模式加锁”时,如果线程以读模式对其加锁会成功。如果线程以写模式加锁会阻塞。(3)读写锁是“读模式加锁”时,如果有另外线程试图以写模式加锁,读写锁通常会阻塞随后的读模式锁请求,这样可以避免...
@property (nonatomic, assign) NSString *title; 什么是assign,copy,retain之间的区别? assign: 简单赋值,不更改索引计数(Reference Counting)。 copy: 建立一个索引计数为1的对象,然后释放旧对象 retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
机器A共享了一个目录,机器B把这个共享目录映射到本地成为一个网络驱动器;后来机器A修改了密码,导致机器B访问网络驱动器出错;想删除这个链接,重新输密码,但在控制台通过net use /delete命令删除这个共享,总提示“引用账户当前已锁定,且可能无法登录”,怎么也删不了。最后没招了,把机器B注销了,再次登陆,无效的网络驱动器已消失,问题解决!