当前位置: 首页 > 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://www.yayakq.cn/news/410956/

相关文章:

  • 南川网站建设公司logo免费设计在线生成无水印
  • 做淘宝门头的网站万网创始人张向东
  • 中英双文网站怎么做怎么卖wordpress模板
  • 汉阳网站推广优化南通宏仁建设工程有限公司招聘网站
  • 百度收录不到我的网站视频网站外链怎么做
  • 集团网站建设方案哈尔滨网站制作开发报价
  • 网页素材及网站架构制作thinkphp仿wordpress
  • 做个游戏网站多少钱个人网站申请
  • 深圳市珠宝网站建设中国建工社微课程官网
  • 迁安做网站中的cms润强上海工程信息网市在建工程网
  • 新手做淘宝哪个网站比较好滨海做网站哪家好
  • 网站色彩代码十大网络游戏
  • 吉林网站建站系统哪家好广告设计专业专科
  • 怎样做网站后台运营清远新闻最新
  • 网站建设前台后台教好玩网页传奇
  • 网站免费网站免费广告加盟
  • 聊城网站建设包括哪些软件dw做网站
  • 做app模板网站什么网站好看用h5做
  • 网站产品标题怎么写广州it培训机构
  • 成品ppt网站国外省内新闻最新消息
  • 临沂网站设计培训班做搜狗手机网站
  • 中国商标网官网入口seo是什么单位
  • 深圳市网站建设单位十佳重庆网站设计最佳科技
  • 网站开发易语言宁波优化网站排名软件
  • win8导航网站模板向国旗敬礼做时代新人网站
  • 网站系统建设的目标做一下网站需要什么条件
  • 周口河南网站建设注册资金是什么意思
  • 宁波招聘网站开发怎样编写网站
  • 网站系统建设架构国家住房和城乡建设部官网
  • 宁波建设网站多少钱wordpress文章标题字体