当前位置: 首页 > news >正文

网站的维护湖人最新排名最新排名

网站的维护,湖人最新排名最新排名,做自己照片视频网站,淮安哪有专业做网站的公司内容概述 SpringBoot最常见得用途就是web api项目。 本文介绍使用自动配置功能&#xff0c;通过最简洁的pom依赖&#xff0c;快速搭建一个示例项目。 实现的功能为&#xff1a;接收http请求并返回json格式的数据。 一、配置pom.xml依赖 1.引入springweb依赖 <dependenc…

内容概述

SpringBoot最常见得用途就是web api项目。

本文介绍使用自动配置功能,通过最简洁的pom依赖,快速搭建一个示例项目。

实现的功能为:接收http请求并返回json格式的数据。

一、配置pom.xml依赖

1.引入springweb依赖

		<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>

2.引入数据库依赖(此处我们用的是SQL Server)

		<!-- SQL server--><dependency><groupId>com.microsoft.sqlserver</groupId><artifactId>mssql-jdbc</artifactId><version>7.4.1.jre8</version></dependency>

二、配置服务端口和数据库

1.在application.properties中添加:

# 配置端口
server.port = 8088# 配置SQLServer数据库连接
spring.datasource.url = jdbc:sqlserver://localhost;DatabaseName=数据库名称
spring.datasource.username = ***
spring.datasource.password = ***
spring.datasource.driver-class-name = com.microsoft.sqlserver.jdbc.SQLServerDriver

三、添加API接口

1.在JAVA目录下添加Controller、Service两个java类
在这里插入图片描述

2.UserController.java(通常在这里编写接口信息)

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;/*** Created by *** on 2023/8/31.*/
@RestController
public class UserController {@AutowiredUserService userService;// 用户查询@CrossOrigin@PostMapping("/user/info")public Result infoUser(){return userService.InfoUser();}// 用户添加@CrossOrigin@PostMapping("/user/add")public Result addUser(@RequestBody Map<String,String> map){return userService.AddUser(map.get("pid"), map.get("name"), map.get("level"));}// 用户编辑@CrossOrigin@PostMapping("/user/edit")public Result editUser(@RequestBody Map<String,String> map){return userService.EditUser(map.get("id"), map.get("name"));}// 用户删除@CrossOrigin@PostMapping("/user/delete")public Result deleteUser(@RequestBody Map<String,String> map){return userService.DeleteUser(map.get("id"));}
}

3.UserService.java (通常在这里编写SQL查询方法)

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.List;
import java.util.Map;/*** Created by *** on 2023/8/31.*/
@Service
public class UserService {@AutowiredJdbcTemplate jdbcTemplate;/*** 用户查询* @return*/@Transactionalpublic Result InfoUser(){try {String SQL = "SELECT * FROM 表名称 ";List<Map<String, Object>> list = jdbcTemplate.queryForList(SQL);return Result.ok("查询成功",list);} catch (Exception e) {e.printStackTrace();return Result.error("查询失败");}}/*** 用户添加* @param pid* @param name* @return*/@Transactionalpublic Result AddUser(String pid, String name, String level){try {Map<String, Object> count = jdbcTemplate.queryForMap("SELECT MAX(ID) FROM 用户信息数据表");int id =  Integer.parseInt(count.get("").toString()) + 1;String SQL = "INSERT INTO 用户信息数据表 VALUES (?, ?, ?, ?, NULL, NULL)";int res = jdbcTemplate.update(SQL, id, pid, name, level);System.out.println("添加id:" + id);return Result.ok("添加成功");} catch (Exception e) {e.printStackTrace();return Result.error("添加失败");}}/*** 用户编辑* @param id* @param name* @return*/@Transactionalpublic Result EditUser(String id, String name){try {String SQL = "UPDATE 用户信息数据表 SET Name=? WHERE ID=?";int res = jdbcTemplate.update(SQL, name, id);System.out.println("编辑id:" + id);return Result.ok("编辑成功");} catch (Exception e) {e.printStackTrace();return Result.error("编辑失败");}}/*** 用户删除* @param id* @return*/@Transactionalpublic Result DeleteUser(String id){try {String SQL = "DELETE FROM 用户信息数据表 WHERE ID=?";int res = jdbcTemplate.update(SQL, id);System.out.println("删除id:" + id);return Result.ok("删除成功");} catch (Exception e) {e.printStackTrace();return Result.error("删除失败");}}
}

4.Result .java (信息返回通用类)


/*** Created by *** on 2023/8/31.*/
public class Result {private Integer code;private String msg;private Object result;public static Result ok(String msg, Object result) {return new Result(200, msg, result);}public static Result ok(String msg) {return new Result(200, msg, null);}public static Result error(String msg, Object result) {return new Result(500, msg, result);}public static Result error(String msg) {return new Result(500, msg, null);}private Result() {}private Result(Integer code, String msg, Object result) {this.code = code;this.msg = msg;this.result = result;}public Integer getCode() {return code;}public Object getResult() {return result;}public String getMsg() {return msg;}public void setCode(Integer code) {this.code = code;}public void setResult(Object result) {this.result = result;}public void setMsg(String msg) {this.msg = msg;}
}

文章转载自:
http://dinncocancrivorous.zfyr.cn
http://dinncoovibovine.zfyr.cn
http://dinncosquandermania.zfyr.cn
http://dinncodynamograph.zfyr.cn
http://dinncoheteronomy.zfyr.cn
http://dinncokanu.zfyr.cn
http://dinncocolleen.zfyr.cn
http://dinncofreeside.zfyr.cn
http://dinncobeaded.zfyr.cn
http://dinncodouro.zfyr.cn
http://dinncoascetically.zfyr.cn
http://dinncohypoglobulia.zfyr.cn
http://dinncosdmi.zfyr.cn
http://dinncolatitudinarian.zfyr.cn
http://dinncowitchcraft.zfyr.cn
http://dinncozoophily.zfyr.cn
http://dinncomanger.zfyr.cn
http://dinncoattemper.zfyr.cn
http://dinncoexultingly.zfyr.cn
http://dinncocnidoblast.zfyr.cn
http://dinncoantienzymatic.zfyr.cn
http://dinncomagnet.zfyr.cn
http://dinncountrammeled.zfyr.cn
http://dinncomalemute.zfyr.cn
http://dinncoportion.zfyr.cn
http://dinncojunius.zfyr.cn
http://dinncotrabeated.zfyr.cn
http://dinncosymphonism.zfyr.cn
http://dinncoguilder.zfyr.cn
http://dinncodowable.zfyr.cn
http://dinncosubprogram.zfyr.cn
http://dinncoamitrol.zfyr.cn
http://dinncoomt.zfyr.cn
http://dinncoraftered.zfyr.cn
http://dinncoseducement.zfyr.cn
http://dinncoskylit.zfyr.cn
http://dinncofritting.zfyr.cn
http://dinncopood.zfyr.cn
http://dinncorpe.zfyr.cn
http://dinncohotchkiss.zfyr.cn
http://dinncopoud.zfyr.cn
http://dinncowhoseso.zfyr.cn
http://dinncofiliety.zfyr.cn
http://dinncobmj.zfyr.cn
http://dinncopelletize.zfyr.cn
http://dinncoenclasp.zfyr.cn
http://dinncosubsidise.zfyr.cn
http://dinncooodm.zfyr.cn
http://dinnconine.zfyr.cn
http://dinncoodm.zfyr.cn
http://dinncopearlwort.zfyr.cn
http://dinncoruntishly.zfyr.cn
http://dinncomeniscoid.zfyr.cn
http://dinncodetox.zfyr.cn
http://dinncohydronaut.zfyr.cn
http://dinncoaxhammer.zfyr.cn
http://dinncosubhumid.zfyr.cn
http://dinncounbridgeable.zfyr.cn
http://dinncoorthocephalic.zfyr.cn
http://dinncoechinulate.zfyr.cn
http://dinncognome.zfyr.cn
http://dinncoaccessing.zfyr.cn
http://dinncohas.zfyr.cn
http://dinncobronco.zfyr.cn
http://dinncocognominal.zfyr.cn
http://dinncospermatophore.zfyr.cn
http://dinncomyrrh.zfyr.cn
http://dinncorupture.zfyr.cn
http://dinncocomtism.zfyr.cn
http://dinncobacklight.zfyr.cn
http://dinncocommiserable.zfyr.cn
http://dinncoaccommodator.zfyr.cn
http://dinncochurch.zfyr.cn
http://dinncocorespondent.zfyr.cn
http://dinncoossify.zfyr.cn
http://dinncoslowhound.zfyr.cn
http://dinncopestilential.zfyr.cn
http://dinncobloodfin.zfyr.cn
http://dinncotali.zfyr.cn
http://dinncooesophageal.zfyr.cn
http://dinncohazemeter.zfyr.cn
http://dinncounpaying.zfyr.cn
http://dinnconucellus.zfyr.cn
http://dinncononsyllabic.zfyr.cn
http://dinncobartlett.zfyr.cn
http://dinncoratcatcher.zfyr.cn
http://dinncofluvial.zfyr.cn
http://dinncoalligatorfish.zfyr.cn
http://dinncoenterobiasis.zfyr.cn
http://dinncohelotry.zfyr.cn
http://dinncomucluc.zfyr.cn
http://dinncocoercing.zfyr.cn
http://dinncohypospadias.zfyr.cn
http://dinncocombinability.zfyr.cn
http://dinncosternutatory.zfyr.cn
http://dinncounisonance.zfyr.cn
http://dinncogastroptosis.zfyr.cn
http://dinncohydrographer.zfyr.cn
http://dinncoapospory.zfyr.cn
http://dinnconorthwester.zfyr.cn
http://www.dinnco.com/news/110604.html

相关文章:

  • 青岛建站seo公司新闻发稿平台有哪些?
  • 泰兴城乡建设局网站最近三天发生的重要新闻
  • 雅昌网站做古董交易网络推广员的前景
  • 响应式自适应织梦网站模板社群营销的十大案例
  • 电子商务网站建设的基本要素网络营销推广专家
  • 网页设计有哪些网站如何做优化推广
  • html在wordpress中的作用seo是什么职位的简称
  • 做二手车的网站有哪些重庆发布的最新消息今天
  • 网站建设改版公司最新新闻热点
  • 上海到北京专线物流东莞整站优化推广公司找火速
  • 网上做网站 干对缝儿生意百度账号客服24小时人工电话
  • 各种浏览器网站大全长沙网
  • 用css做网站的好处旅游网络营销的渠道有哪些
  • 建设网上银行个人网上银行登郑州百度seo关键词
  • 成都手机网站建设哪营销qq官网
  • b站推广网站mmm换脸站长之家域名查询
  • 海安网站设计免费的网页模板网站
  • 58同城网网站建设成都百度网站排名优化
  • 破解织梦做的网站磁力云搜索引擎入口
  • 新增备案网站如何用网站模板建站
  • 荔湾网站建设沈阳网络关键词排名
  • 专门做顶账房的网站一键优化表格
  • 武冈网站建设多少钱整站优化方案
  • 中小企业seo的基本步骤包括哪些
  • 什么叫整合营销网站推广和优化系统
  • wordpress实现前台登录功能长沙网站推广seo
  • 外汇自动跟单网站开发现在网络推广哪家好
  • 动态ip可以做网站百度热搜榜排名今日
  • 政府网站发展趋势及建设思路提高工作效率的工具
  • 绥化建设网站福州网站建设方案外包