springboot搭建以及常用注解
来源:互联网 发布:淘宝网包包货到付款 编辑:程序博客网 时间:2024/06/06 02:39
springboot搭建以及常用注解
1. springboot运行环境
1.1. java环境
jdk7.0及其以上 maven3.0+
1.2. 添加jar包依赖
新建maven web项目,在pom.xml中添加一下依赖
<!-- springboot begin --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>1.5.2.RELEASE</version></dependency><dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version></dependency><!-- springboot end --><!-- jdbc begin --><dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version></dependency><dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>10.2.0.4.0</version></dependency><dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version></dependency><!-- jdbc end --><!-- tomcat-jsp begin --><dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <version>8.5.6</version></dependency><dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version></dependency><!-- tomcat-jsp end -->
2. springboot构建
2.1. 启动类 (main方法启动)
由于springboot启动默认扫描启动类同包及其子包,所以该启动类需要放在所有包外。示例项目结构如下:
package com.zhangjie.springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ComponentScan;import org.springframework.transaction.annotation.EnableTransactionManagement;/** * @Description: 启动类*/@SpringBootApplication public class Application {public static void main(String[] args) { System.setProperty("server.port", "8080"); //do config springboot server port SpringApplication.run(Application.class, args); }}
启动类上常用注解
2.2. controller编写
package com.zhangjie.springboot.controller;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import com.zhangjie.springboot.domain.Account;import com.zhangjie.springboot.service.UserService;@Controller@RequestMapping("/user")public class UserController { @Resource(name = "userService") UserService userService; @RequestMapping(value="/getlist", method = RequestMethod.POST) @ResponseBody public List<Account> getlist(String id){ return userService.getList(); } /*@RequestMapping(value="/getlist/{id}", method = RequestMethod.POST) @ResponseBody public List<Account> getUserById(@PathVariable("id") String id){ return userService.getList(); }*/ @RequestMapping(value = "/user.htm", method = RequestMethod.GET) public String getUserById(@RequestParam(value="id", required=false) String id){ return "user"; } @RequestMapping(value = "/login.htm", method = RequestMethod.GET) public String login(){ return "login"; }}
controller中常用注解
2.3. ajax调用
与普通ajax调用一样
<script type="text/javascript">$(function(){ $.ajax({ url:"localhost:8080/user/getlist", type:"POST", dataType:"json", success:function(data){ console.log(data); } })})</script>
启动项目,访问http://localhost:8080/user/login.htm,即可跳转到login.jsp页面;在jsp中写入上JavaScript代码调用post方法,即可访问controller中getlist方法,后台读取数据整合了mybatis这里未贴出代码。
0 0
- springboot搭建以及常用注解
- springboot 常用注解
- springboot常用注解二
- 常用springboot注解
- springboot常用注解总结
- SpringBoot常用注解
- SpringBoot常用注解
- SpringBoot常用注解
- Springboot 常用注解
- 【SpringBoot】常用注解
- Springboot 常用注解
- SpringBoot一些常用注解
- springboot常用注解集锦
- springboot常用注解
- Springboot 常用注解
- springBoot Restfull 常用注解
- SpringBoot常用注解
- java springboot常用注解
- Top K
- N-Queens
- typedef与define的区别
- 【OpenGL】OpenGL引擎开发视频教程
- 在Mac下安装GDAL-Python
- springboot搭建以及常用注解
- Android开发环境的搭建
- ACL_2017深度学习前沿论文分享(2)
- php pdo连接数据库
- iOS 性能调试Instruments ->Time Profiler
- 小程序ios 和 android 的 布局兼容问题
- VCSA 6.0 (版本号2562643)正式版安装指南
- linux 下每隔5分钟执行某个任务
- UITextView 行间距设置