JavaEE-SSM整合

简介: JavaEE-SSM整合

请求状态提示


根据 状态码 判断

“StatusCode”: 100,

表示数据不为空

“StatusDescription”: “请求成功。”,

提示“请求成功。”

  "DataStatus": {
    "RequestParameter": "keywords=烽火&pagesize=10&pagenumber=1&type=&searchtype=all",
    "StatusCode": 100,
    "StatusDescription": "请求成功。",
    "ResponseDateTime": "2021-06-10 09:25:05",
    "DataTotalCount": 244
  },


Update


根据id更改


Add


id自增,不用写

返回的“1”为改变的行数,新增了一行即改变了一行。


Delete


根据id删除


FindAll


查询全部


FindById


根据id查询


CustomerDao.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.CustomerDao">
    <!--根据id查询-->
    <select id="findCustomerById" parameterType="Integer" resultType="Customer">
        select * from t_customer where id =#{id}
    </select>
<!--    查询所有用户-->
    <select id="findAllCustomer" resultType="Customer">
        select * from t_customer
    </select>
<!--    删-->
    <delete id="deleteCustomer" parameterType="Integer">
        delete from t_customer where id=#{id}
    </delete>
<!--    增-->
    <insert id="addCustomer" parameterType="Customer">
        insert into t_customer(username,jobs,phone) values (#{username},#{jobs},#{phone})
    </insert>
<!--    改-->
    <update id="updateCustomer" parameterType="Customer">
        update t_customer
        <set>
            <if test="username !=null and username !=''">
                username =#{username},
            </if>
            <if test="jobs !=null and jobs !=''">
                jobs =#{jobs},
            </if>
            <if test="phone !=null and phone !=''">
                phone =#{phone},
            </if>
        </set>
        where id=#{id}
    </update>
</mapper>

还有个CustomerDao.java接口与CustomerService.java差不多


CustomerService


package com.service;
import com.po.Customer;

import java.util.List;

public interface CustomerService {
    public Customer findCustomerById(Integer id);
    public List<Customer> findAllCustomer();
    public int deleteCustomer(Integer id);
    public int addCustomer(Customer customer);
    public int updateCustomer(Customer customer);
}


CustomerServiceImpl


package com.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dao.CustomerDao;
import com.po.Customer;
import com.service.CustomerService;

import java.util.List;

@Service
//注解@Transactional作用:对数据的增、修、改进行事务管理
@Transactional
public class CustomerServiceImpl implements CustomerService {
    //注解注入CustomerDao
    @Autowired
    private CustomerDao customerDao;
    //查询客户
    public Customer findCustomerById(Integer id) {
        return this.customerDao.findCustomerById(id);
    }

    @Override
    public List<Customer> findAllCustomer() {
        return this.customerDao.findAllCustomer();
    }

    @Override
    public int deleteCustomer(Integer id) {
        return this.customerDao.deleteCustomer(id);
    }

    @Override
    public int addCustomer(Customer customer) {
       return this.customerDao.addCustomer(customer);
    }

    @Override
    public int updateCustomer(Customer customer) {
        return this.customerDao.updateCustomer(customer);
    }
}


CustomerController


package com.controller;

import com.po.Customer;
import com.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @ResponseBody
    @RequestMapping("/findCustomerById")
    public Customer findCustomerById(Integer id) {
        Customer customer = customerService.findCustomerById(id);
        return customer;
    }
//    查询所有
    @ResponseBody
    @RequestMapping("/findAllCustomer")
    public List<Customer> findAllCustomer(){
        List<Customer> customers = customerService.findAllCustomer();
        return customers;
    }
    //删
    @ResponseBody
    @RequestMapping("/deleteCustomer")
    public int deleteCustomer(Integer id) {
        return customerService.deleteCustomer(id);//返回改变的(删除的)行数
    }
    //增
    @ResponseBody
    @RequestMapping("/addCustomer")
    public int addCustomer(@RequestBody Customer customer) {
        return customerService.addCustomer(customer);
    }
    //改
    @ResponseBody
    @RequestMapping("/updateCustomer")
    public int updateCustomer(@RequestBody Customer customer) {
        return customerService.updateCustomer(customer);
    }
}
相关文章
|
人工智能 数据可视化
用了这8款AI制作PPT软件,年终总结再也不是问题!
8款好用的AI生成PPT软件推荐,轻松解决你的年终总结!
|
机器学习/深度学习 小程序 数据挖掘
Multi-Agent 的灵活编排之路
本文探讨了Copilot 3.0架构中规划模块结合DeepSeek R1强化学习(GRPO)的实践,重点分析多智能体架构下大模型如何灵活调度多个智能体解决实际问题。文章从背景、问题分析、Planning角色、难点、效果对比到解决方案进行了深入讲解,并通过实验现象展示了有无思考过程对模型性能的影响。结果显示,GRPO训练后推理长度显著降低,准确率提升7.4个百分点,同时解决了复杂问题与简单问题处理间的平衡问题。
1661 11
Multi-Agent 的灵活编排之路
|
架构师 算法 Java
阿里年薪百万的P7架构师简历都长什么样?他们都是怎么学习的?
我有一个朋友最近想从一个中型企业跳槽到大厂,目标瞄准了美团、滴滴、字节跳动等大厂,但投了简历,都石沉大海了!
|
Linux
支持exfat和ntfs格式的U盘
该文档提供了在Linux系统中支持exFAT和NTFS格式U盘的方法。首先,通过安装EPEL库(需管理员权限)开始,使用`yum -y install epel-release`命令。接着,对于RHEL/CentOS 7,需添加Nux Dextop仓库并安装exfat支持库,命令为`rpm -Uvh
1022 0
mac系统使用NTFS移动硬盘只读问题
mac系统使用NTFS移动硬盘只读问题
607 4
|
PyTorch 算法框架/工具 索引
Pytorch函数view、permute、squeeze、usqueeze
Pytorch函数view、permute、squeeze、usqueeze
501 0
|
3天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8094 2
|
12天前
|
域名解析 人工智能 Linux
|
20天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10624 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置