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 ...
随机推荐
- 04 Spring框架 依赖注入(一)
整理了一下之前学习spring框架时候的一点笔记.如有错误欢迎指正,不喜勿喷. 上一节我们讲了几个bean的一些属性,用来限制我们实例创建过后的状态. 但是细心的我们会发现其实上面demo创建的实例并 ...
- PAT 天梯赛 L1-034. 点赞 【MAP】
题目链接 https://www.patest.cn/contests/gplt/L1-034 AC代码 #include <cstdio> #include <cstring> ...
- C# 学习黑马.Net视频教程,大文件拷贝
设计器代码: namespace 大文件拷贝 { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </summary> ...
- DataTable Group By或运算 Linq Aggregate的使用
class Program { static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add(&qu ...
- Windos Server 2008 Tomcat 安装
web服务:apache-tomcat-7.0.75环境:jdk-7u80-windows-i586 1.安装jdk环境包 2.配置环境变量--> 环境变量--> 新建W --> 变 ...
- awk遇到windows 的^M
windows在编辑的文档,在linux中显示会在行尾出现一个^M window下编辑的文档:末尾带^M$ linux下编辑的文档:末尾带$ awk中如果存在^M,则会限制print的输出列数(只能输 ...
- java内置注解、元注解和自定义注解
注解的作用: 1.生成文档 2.跟踪代码依赖性 3.编译时进行格式检查 ---------------------------------------------------------------- ...
- CentOS 6.5 下的截图方法
1.利用命令模式 捕获整个屏幕 : $ gnome-screenshot 截完屏之后我们可以设置自定义图片存储位置,如图: 捕获当前终端Terminal : $ gnome-screenshot -w ...
- IIS部署PHP项目并与mysql完美结合
在上一篇文章中,提到iis与apache共用80端口,但是发现很多问题,例如 IIS网站有支付功能,而微信支付是不支持带有端口的网址的,虽然通过apche代理,在外面看来没有端口,可是内部还是避免不了 ...
- linux下firefox显示中文乱码的问题
只需要yum install "@Chinese Support" 然后注销,再登录一下,刷新浏览器就可以正常显示中文了,当然前提是浏览器的字符编码为utf-8以及默认显示中文,这 ...