模拟数据库演示springboot小测试

1、编写一个实体类:user

 package com.wisezone.test;

 import java.io.Serializable;

 public class User implements Serializable {

     private Integer userId;//用户id
private String userName;//用户名
private String age;//用户年龄
private String address;//用户地址 public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
} public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
} public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
} public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} }

2、编写一个dao:userDao

 package com.wisezone.test;

 import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository; @Repository
public class UserDao {
private static final Logger logger = LoggerFactory.getLogger(UserDao.class); public User findUser(String userName) {
logger.info("根据用户名查询:{}",userName);
User user = new User();
user.setUserId(10);
user.setUserName("上海上海");
user.setAge("20");
user.setAddress("上海市浦东新区上浦路888弄888号888室");
return user;
}
}

3、编写一个service:userService

 package com.wisezone.test;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; @Service
public class UserService { @Autowired
private UserDao userDao; public User findUserByUserName(String userName) {
return userDao.findUser(userName);
}
}

4、编写一个controller:userController

 package com.wisezone.test;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @RequestMapping("user")
@Controller
public class UserController
{
@Autowired
private UserService userService; @RequestMapping("find")
@ResponseBody
public User findUser(String userName) { return userService.findUserByUserName(userName);
}
}

5、main方法测试

 package com.wisezone.test;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Console:

浏览器:http://localhost:8080/user/find/?userName=hello

Springboot演示小Demo的更多相关文章

  1. springBoot+mybatisPlus小demo

    项目介绍:采用restful api进行接口规范 / 项目框架SpringBoot+mybatis Plus / 采用mysql进行数据存储 / 采用swaggerUI进行前后端业务分离式开发. 开发 ...

  2. IntelliJ IDEA搭建SpringBoot的小Demo

    首先简单介绍下Spring Boot,来自度娘百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进 ...

  3. 1.IntelliJ IDEA搭建SpringBoot的小Demo

    转自:http://www.cnblogs.com/weizaibug/p/6657077.html 首先简单介绍下Spring Boot,来自度娘百科:Spring Boot是由Pivotal团队提 ...

  4. Nancy之基于Nancy.Hosting.Self的小Demo

    继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后, 今天来做个基于Nancy.Hosting.Self的小Demo. 关于Self Hosting Nancy,官方文档的 ...

  5. Nancy之基于Nancy.Owin的小Demo

    前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...

  6. 多线程之批量插入小demo

    多线程之批量插入 背景 昨天在测试mysql的两种批量更新时,由于需要入库大量测试数据,反复执行插入脚本,过程繁琐,档次很低,测试完后我就想着写个批量插入的小demo,然后又想写个多线程的批量插入的d ...

  7. jsoup爬虫简书首页数据做个小Demo

    代码地址如下:http://www.demodashi.com/demo/11643.html 昨天LZ去面试,遇到一个大牛,被血虐一番,发现自己基础还是很薄弱,对java一些原理掌握的还是不够稳固, ...

  8. SpringBoot-Vue实现增删改查及分页小DEMO

    前言 主要通过后端 Spring Boot 技术和前端 Vue 技术来简单开发一个demo,实现增删改查.分页功能以及了解Springboot搭配vue完成前后端分离项目的开发流程. 开发栈 前端 开 ...

  9. RPC框架学习+小Demo实例

    一.什么是RPC协议? 全称:远程过程调度协议 效果:使消费者向调用本地方法一样调用远程服务方法,对使用者透明 目前常用:Dubbo.Thirft.Sofa.... 功能: 建立远程通信(socket ...

随机推荐

  1. a各种状态

    hover   设置对象在其鼠标悬停时的样式表属性 active  设置对象在被用户激活(在鼠标点击与释放之间发生的事件)时的样式表属性.link  设置a对象在未被访问前的样式表属性.visited ...

  2. PAT 天梯赛 L1-023. 输出GPLT 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-023 AC代码 #include <iostream> #include <cstdio&g ...

  3. Springboot WebSocket例子

    Springboot整合WebSocket 1.application.properties #设置服务端口号 server.port=8080 #thymeleaf配置 #是否启用模板缓存. spr ...

  4. Linux用户和用户组管理 用户管理相关命令

    用户添加命令 useradd 注意: 新添加的用户如果不设定密码是不能够登录系统的 命令格式: [root@localhost ~]#useradd [选项] 用户名 选项说明: 选项 选项说明 -u ...

  5. Django框架之自定义分页

    分页功能在每个网站都是必要的,对于分页来说,其实就是根据用户的输入计算出应该在数据库表中的起始位置. 1.设定每页显示数据条数 2.用户输入页码(第一页.第二页...) 3.根据设定的每页显示条数和当 ...

  6. [POI2007]立方体大作战tet

    题目 BZOJ 洛谷 做法 很巧妙的题,注意每种颜色只有两个 消除一种颜色,其实就是看中间有多少个没有被消除的块,这种动态距离问题显然能用树状数组解决 洛谷输出方案,暴力往下爬就行 My comple ...

  7. python之json模块的基本使用

    json模块的作用:将字符串和字典相互转换 json和eval的区别: eval函数不能识别null转换成None json可以将null转换成python可以识别的None json序列化和反序列化 ...

  8. juniper设置共享上网(注意事项)

    注意:出去的 策略  ,勾上  NAT 选项  

  9. RHCE学习笔记 管理1 (第三~五章)

    第三章 红帽企业linux 获取帮助 (略) man .pinfo. 第四章 编辑文件 1.输出重定向到文件和程序 >file    定向文件(覆盖) >>file   定向文件(附 ...

  10. oracle 计算时间差

    1.计算时间差(相隔星期,天数,小时,分钟,秒) SELECT TO_CHAR(date1,'MMDDYYYY:HH24:MI:SS') date1, TO_CHAR(date2,'MMDDYYYY: ...