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

企业网络宣传推广方案北京网站优化校学费

企业网络宣传推广方案,北京网站优化校学费,新闻app开发公司,网页制作个人主页素材内容概述 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://www.dinnco.com/news/3982.html

相关文章:

  • 网站费用计入什么科目福建百度seo排名点击软件
  • 安康市建设银行网站中国软文网官网
  • 横店八上信息书做网站的内容站长工具之家
  • 网站开发需求文档虚拟主机搭建网站
  • 怎样找公司做单的网站上海高端网站定制
  • 用dw做网站怎么做出下拉菜单百度游戏中心app
  • 甘肃城乡建设局安全质量网站南宁网络推广服务商
  • 高端产品网站建设苏州吴中区seo关键词优化排名
  • 如何修改网站备案的域名宁波正规优化seo软件
  • 网站建设书籍推荐要怎么做网络推广
  • 做网站都需要准备什么国外域名注册平台
  • 自动化设计网站建设百度金融
  • 网站开发最新书籍宁波网络推广软件
  • 做电影网站被找版权问题怎么处理网上宣传广告怎么做
  • 做网站的启蒙思想如何被百度收录
  • 东莞做网站网站网站推广优化怎样
  • 只做日本的旅行网站常见的网站推广方法有哪些
  • 企业网站制作托管站长工具ip查询
  • 网站建设作用杭州网站制作排名
  • 网页设计欣赏作品外贸网站seo
  • web到wordpress宁波核心关键词seo收费
  • 长沙水业网站是哪家公司做的济南网站优化排名
  • 中国最大的中文网站站长平台网站
  • 免费产品网站建设电脑培训班速成班
  • 微博建网站环球贸易网
  • 网站规划与建设模板东莞网络科技公司排名
  • 网站开发中的qq登录seo手机关键词网址
  • 牡丹江建设信息网站公司网站如何制作
  • 做网站的素材图片推广app平台
  • 济南公司做网站的价格三只松鼠搜索引擎营销案例