Springboot演示小Demo
模拟数据库演示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的更多相关文章
- springBoot+mybatisPlus小demo
项目介绍:采用restful api进行接口规范 / 项目框架SpringBoot+mybatis Plus / 采用mysql进行数据存储 / 采用swaggerUI进行前后端业务分离式开发. 开发 ...
- IntelliJ IDEA搭建SpringBoot的小Demo
首先简单介绍下Spring Boot,来自度娘百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进 ...
- 1.IntelliJ IDEA搭建SpringBoot的小Demo
转自:http://www.cnblogs.com/weizaibug/p/6657077.html 首先简单介绍下Spring Boot,来自度娘百科:Spring Boot是由Pivotal团队提 ...
- Nancy之基于Nancy.Hosting.Self的小Demo
继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后, 今天来做个基于Nancy.Hosting.Self的小Demo. 关于Self Hosting Nancy,官方文档的 ...
- Nancy之基于Nancy.Owin的小Demo
前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...
- 多线程之批量插入小demo
多线程之批量插入 背景 昨天在测试mysql的两种批量更新时,由于需要入库大量测试数据,反复执行插入脚本,过程繁琐,档次很低,测试完后我就想着写个批量插入的小demo,然后又想写个多线程的批量插入的d ...
- jsoup爬虫简书首页数据做个小Demo
代码地址如下:http://www.demodashi.com/demo/11643.html 昨天LZ去面试,遇到一个大牛,被血虐一番,发现自己基础还是很薄弱,对java一些原理掌握的还是不够稳固, ...
- SpringBoot-Vue实现增删改查及分页小DEMO
前言 主要通过后端 Spring Boot 技术和前端 Vue 技术来简单开发一个demo,实现增删改查.分页功能以及了解Springboot搭配vue完成前后端分离项目的开发流程. 开发栈 前端 开 ...
- RPC框架学习+小Demo实例
一.什么是RPC协议? 全称:远程过程调度协议 效果:使消费者向调用本地方法一样调用远程服务方法,对使用者透明 目前常用:Dubbo.Thirft.Sofa.... 功能: 建立远程通信(socket ...
随机推荐
- ajax使用formdata 提交excel文件表单到rails解析
.modal-body .container-fluid .row .col-md-12 1.下载模板文件 = link_to '模板文件' .row .col-md-12 = form_tag '' ...
- Python学习进程(11)日期和时间
本节介绍Python应用程序处理时间和日期的方式.其中转换日期格式是最常用的功能. (1)获取时间戳: Python 提供了一个 time 和 calendar 模块可以用于格式化日期 ...
- 一个不成熟的编程员,写写 js 的面向对象
其实感觉本人 js 并未入门,甚至说也是个不合格的编程员,什么面向对象都不会,一直都往 Object 里面填方法,假装很对象的样子. 但学习嘛,这道坎还是得多试几下的,说不定就跨过去了呢. 个人喜欢用 ...
- nodejs实现静态托管
const express = require("express"); const app = express(); /* 语法1: app.use(express.static( ...
- usb mtp激活流程【转】
本文转载自:https://blog.csdn.net/kc58236582/article/details/46895901 废话少说, 先上两张时序图 , 图片有点大, 建议用新窗口打开或者另存到 ...
- vRA7 Software Component
将自定义Property传递给Software Component 示例: vRA7 支持 Software Components,并且还可以在用户的申请页面中,做一个下拉菜单,让用户选择需要安装的S ...
- EntityFramework 学习 一 Multiple Diagrams in Entity Framework 5.0
Visual Studio 2012 provides a facility to split the design time visual representation of the Entity ...
- [转]Android:改变Activity切换方式
overridePendingTransition(enterAnim, exitAnim); Intent intent =new Intent(this,item2.class); startAc ...
- VC查找字符串
第一种方式#include "stdafx.h" #include <string.h> #include <stdio.h> #include <W ...
- UVA 10200 Prime Time 水
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...