SSM的整合

10 篇文章 0 订阅
1 篇文章 0 订阅

1. spring的配置

主要有三个方面的主要配置:

1.  数据源配置

2.  sqlSessionFactory 整合mybatis

3.  为dao接口生成代理实现类

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--    扫描包-->
    <context:component-scan base-package="com.sfc"/>
<!--    注释-->
    <mvc:annotation-driven/>
<!--    静态资源放行-->
    <mvc:default-servlet-handler/>

    <!--    spring的配置-->
    <!--    数据源配置-->
    <bean id="ds" class="com.alibaba.druid.pool.DruidDataSource">
        <!--        驱动名称-->
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Shanghai"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <!--        初始化连接池的个数-->
        <property name="initialSize" value="5"/>
        <!--        至少的个数-->
        <property name="minIdle" value="5"/>
        <!--        最多的个数-->
        <property name="maxActive" value="10"/>
        <!--        等待的最长时间  单位毫秒-->
        <property name="maxWait" value="3000"/>
    </bean>

    <!--    sqlSessionFactory  整合mybatis-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="ds"/>
        <!--        设置mybatis映射文件的路径-->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">

                </bean>
            </array>
        </property>
    </bean>


    <!--    为dao接口生成代理实现类-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--        为com.sfc.dao包的接口下生成代理实现类-->
        <property name="basePackage" value="com.sfc.dao"/>
    </bean>
</beans>

2.  web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

3. pom.xml的包

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sfc</groupId>
  <artifactId>ssm_0615</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>

    <!--spring-webmvc-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.2.15.RELEASE</version>
    </dependency>

    <!--mybatis依赖-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.6</version>
    </dependency>

    <!--mybatis和spring整合的依赖-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>2.0.6</version>
    </dependency>

    <!--mysql驱动-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.28</version>
    </dependency>

    <!--druid连接池依赖-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.2.1</version>
    </dependency>

    <!--lombok依赖-->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.24</version>
    </dependency>

    <!--jackson java对象转换为json对象 @ResponseBody-->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.13.2.2</version>
    </dependency>

    <!--servlet-api依赖-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.2.15.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-core</artifactId>
      <version>1.4.0</version>
    </dependency>

    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.3.0</version>
    </dependency>
  </dependencies>
</project>

4.  generator自动生成的配置文件

(1)配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <!--找到你的mysql驱动jar的位置-->
    <classPathEntry location="D:\mavenanzhuang\repMaven\mysql\mysql-connector-java\8.0.28\mysql-connector-java-8.0.28.jar" />

    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据源的配置信息-->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Shanghai"
                        userId="root"
                        password="root">
        </jdbcConnection>

        <javaTypeResolver >
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!--java实体类的配置-->
        <javaModelGenerator targetPackage="com.sfc.entity" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <!--映射文件的配置-->
        <sqlMapGenerator targetPackage="mapper"  targetProject=".\src\main\resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <!--dao数据访问层的配置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.sfc.dao"  targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <!--数据库表和实体的映射关系
              schema:数据库名称
              tableName: 表名
              domainObjectName:实体类名

              enableUpdateByExample:是否生成复杂的修改操作
        -->
        <table schema="mydb" tableName="student" domainObjectName="Student"
               enableUpdateByExample="false" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false">

        </table>

        <table schema="mydb" tableName="tba_user" domainObjectName="User"
               enableUpdateByExample="false" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false">

        </table>

    </context>
</generatorConfiguration>

(2)测试类

package com.sfc.test;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * author  : sfc
 *
 * @date : 2022-06-14 16:17
 */
public class GeneratorTest {
    public static void main(String[] args) throws Exception{
        List<String> warnings = new ArrayList<String>();
        Boolean overwrite = true;
        File configFile = new File("generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback,warnings);
        myBatisGenerator.generate(null);
    }
}

5. 新建一个包utils下一个类CommonResult

package com.sfc.utils;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 15:57
 */
public class CommonResult {
    private int code;
    private String msg;
    private Object data;

    @Override
    public String toString() {
        return "CommonResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public CommonResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public CommonResult() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

6.  登录功能

6.1  前端页面

<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2022/5/28
  Time: 21:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <script type="text/javascript" src="js/vue.min.js"></script>
    <script type="text/javascript" src="js/qs.min.js"> </script>
    <script type="text/javascript" src="js/axios.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <link type="text/css" rel="stylesheet" href="css/index.css">
    <style>
        body,.box{
            overflow: hidden;
            height: 100%;
        }
        .box{
            background: url("imgs/beijing1.png");
        }
        #form>.avatar_box{
            height: 130px;
            width: 130px;
            border: 1px solid #eee;
            border-radius: 50%;
            padding: 10px;
            box-shadow: 0 0 10px #ddd;
            position: absolute;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #fff;
        }
        #form>.avatar_box>img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background-color: #eee;
        }
        .login_form {
            position: absolute;
            bottom: 0;
            width: 100%;
            padding: 0 20px;
            box-sizing: border-box;
        }


        #form{
            width:450px;
            height:300px;
            border:3px solid grey;
            position: absolute;
            left:50%;
            top:50%;
            transform: translate(-50%,-50%);
            padding:30px 20px;
        }
    </style>
</head>
<!-- 背景图片-->
<body background="imgs/beijing1.png">
  <div id="app">
      <div class="box">
          <div id="form">
              <!-- 登录图标-->
                  <div class="avatar_box">
                      <img src="imgs/login.png" />
                  </div>
                  <div style="margin: 20px;"></div>
                  <el-form  label-width="80px" :model="loginForm" :rules="loginRules" ref="loginRuleForm">
                      <el-form-item label="账号" prop="username">
                          <el-input v-model="loginForm.username"></el-input>
                      </el-form-item>
                      <el-form-item label="密码" prop="password">
                          <el-input v-model="loginForm.password"></el-input>
                      </el-form-item>
                      <el-form-item>
                          <el-button type="primary" @click="submitForm()">登录</el-button>
                          <el-button type="primary" @click="zhuce()">注册</el-button>
                          <el-button >重置</el-button>
                      </el-form-item>

                  </el-form>
          </div>
      </div>

  </div>
<script>
   var app = new Vue({
       el:"#app",
       data:{
           //定义登录表单
           loginForm:{},
           loginRules:{
               username:[
                   { required: true, message: '请输入账号', trigger: 'blur' },
                   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
               ],
               password:[
                   { required: true, message: '请输入密码', trigger: 'blur' },
                   { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
               ],
           },
       },
       methods:{
           //定义登录的方法,登录
           submitForm(){
               //校验通过后
               this.$refs['loginRuleForm'].validate((valid) => {
                   if (valid) {
                       var that = this;
                       var qs = Qs;
                       //调用axios方法
                       axios.post("/user/login" , qs.stringify(this.loginForm) ).then(function(result){
                           console.log(result);
                           if(result.data.code===2000){
                              // 跳转到成功页面
                               location.href="xinxi.jsp";
                               //弹出成功信息
                               that.$message.success(result.data.mag);
                           }else{
                               //弹出失败信息
                               that.$message.error(result.data.mag);
                           }
                       })

                   }
               })
           },
           //注册的方法
           zhuce(){
               this.$refs['loginRuleForm'].validate((valid) => {
                   if (valid) {
                       var that = this;
                       var qs = Qs;
                       //调用axios方法
                       axios.post("loginServlet?method=zhuce",qs.stringify(this.loginForm)).then(function(result){
                           console.log(result);
                           if(result.data.code===2000){
                               that.$alert(result.data.mag, '注册状态', {
                                   confirmButtonText: '确定',
                                   callback: action => {
                                       that.$message({
                                           type: 'info',
                                           message: `action: ${ action }`
                                       });
                                   }
                               });
                           }
                       })
                   }
               })
           }
       }
   })
</script>
  </body>
</html>

效果图

6.2  controller层代码

package com.sfc.controller;

import com.sfc.entity.User;
import com.sfc.service.UserService;
import com.sfc.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpSession;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 15:48
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

    @Autowired
    private UserService userService;

    //测试
    @RequestMapping(value = "hello")
    public User find(Integer id){
        User user = userService.findId(id);
        return user;
    }

    //密码验证
    @RequestMapping(value = "login")
    public CommonResult find(User user , HttpSession session){
        User pdw = userService.findPdw(user);
        if (pdw!=null){
            session.setAttribute("user",pdw);
            return new CommonResult(2000,"成功",null);
        }
        return new CommonResult(5000,"失败",null);
    }
}

6.3  service业务层

6.3.1  接口

package com.sfc.service;

import com.sfc.entity.User;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 15:44
 */
public interface UserService {
    public User findId(Integer id);

    //查询密码
    public User findPdw(User user);
}

6.3.2  service业务工厂代码

package com.sfc.service.abc;

import com.sfc.dao.UserMapper;
import com.sfc.entity.User;
import com.sfc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 15:45
 */
@Service
public class UserServiceAbc implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findId(Integer id) {
        User user = userMapper.selectByPrimaryKey(id);
        return user;
    }

    @Override
    public User findPdw(User user) {
        User selectpws = userMapper.selectpws(user);
        return selectpws;
    }
}

6.4  在dao包下userMapper中添加一个方法

User selectpws(User user);

6.5  在Mapper映射文件中添加对应的查询

 <select id="selectpws" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tba_user
    where username = #{username} and  password = #{password}
  </select>

7.  学生信息管理系统的增删改查

7.1  前端页面展示

代码:

<%--
  Created by IntelliJ IDEA.
  User: sfc
  Date: 2022-06-18
  Time: 15:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息管理系统</title>
    <link type="text/css" rel="stylesheet" href="css/index.css"/>
    <script type="text/javascript" src="js/vue.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/axios.min.js"></script>
    <script type="text/javascript" src="js/qs.min.js"></script>
</head>
<body>
<div id="app">
    <!--    添加-->
    <el-button type="primary" @click="dialogVisible = true" round>添加学生信息</el-button>
    <el-dialog
            title="添加学生信息"
            :visible.sync="dialogVisible"
            width="30%">
        <!--        :model绑定表单数据-->
        <el-form :model="addform">
            <el-form-item label="姓名" label-width="40px">
                <el-input v-model="addform.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="年龄" label-width="40px">
                <el-input v-model="addform.age" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="城市" label-width="40px">
                <el-input v-model="addform.address" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="insert">确 定</el-button>
        </span>
    </el-dialog>

    <el-table
            :data="tableData"
            border
            style="width: 100%">
        <el-table-column
                prop="id"
                label="编号">
        </el-table-column>
        <el-table-column
                prop="name"
                label="姓名">
        </el-table-column>
        <el-table-column
                prop="age"
                label="年龄">
        </el-table-column>
        <el-table-column
                prop="address"
                label="地址">
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作">
            <template slot-scope="scope">
                <el-button type="danger" @click="del(scope.row.id)" icon="el-icon-delete" round>删除学生</el-button>
                <el-button type="warning"  @click="update(scope.row)" icon="el-icon-edit" round>修改信息</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-dialog
            title="修改学生信息"
            :visible.sync="updates"
            width="30%">
        <!--        :model绑定表单数据-->
        <el-form :model="upform">
            <el-form-item label="姓名" label-width="40px">
                <el-input v-model="upform.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="年龄" label-width="40px">
                <el-input v-model="upform.age" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="城市" label-width="40px">
                <el-input v-model="upform.address" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button @click="updates = false">取 消</el-button>
            <el-button type="primary" @click="edit()">确 定</el-button>
        </span>
    </el-dialog>
</div>
</body>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            tableData: [],
            dialogVisible:false,
            addform:{},
            updates:false,
            upform:[]

        },
        created(){
            this.selectAll();
        },
        methods:{
            edit(){
                var qs = Qs;
                var that = this;
                axios.post("student/update",qs.stringify(that.upform)).then(function (result){
                    that.updates = false;
                    //console.log(result.data.code)
                    that.$message.success(result.data.mag);
                    if (result.data.code===2000){
                        that.selectAll();
                    }
                })
            }
            ,
            update(row){
                this.updates = true;
                this.upform = row;
            },
            selectAll(){
                var that = this;
                axios.get("student/student").then(function (result){
                    if (result.data.code===2000){
                        that.tableData = result.data.data;
                        //console.log(result)
                    }
                })
            },
            insert(){
                var qs = Qs;
                var that = this;
                axios.post("student/add",qs.stringify(this.addform)).then(function (result){
                    if (result.data.code===2000){
                        that.$message.success(result.data.mag);
                        that.dialogVisible = false;
                        that.selectAll();
                    }
                })
            },
            del(id){
                //alert(id);
                var qs = Qs;
                var that = this;
                axios.post("student/delete",qs.stringify({"method":"delete","id":id})).then(function (result){
                    console.log(result.data)
                    if (result.data.code===2000){
                        that.$message({
                            message:result.data.mag,
                            type:'success'
                        })
                        that.selectAll();
                    }
                })
            }
        }
    })
</script>
</html>

效果:

7.2 controller层 

package com.sfc.controller;

import com.sfc.entity.Student;
import com.sfc.service.StudentService;
import com.sfc.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 16:17
 */
@RestController
@RequestMapping(value = "student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //所有信息
    @RequestMapping(value = "student")
    public CommonResult selectAll(){
        List<Student> list = studentService.selectAll();
        return new CommonResult(2000,"成功",list);
    }

    //添加
    @RequestMapping(value = "add")
    public CommonResult add(Student student){
        int insert = studentService.insert(student);
        if (insert==1){
            return new CommonResult(2000,"成功",null);
        }
        return new CommonResult(5000,"失败",null);
    }

    //修改
    @RequestMapping(value = "update")
    public CommonResult update(Student student){
        int i = studentService.update(student);
        if (i==1){
            return new CommonResult(2000,"成功",null);
        }
        return new CommonResult(5000,"失败",null);
    }

    //删除
    @RequestMapping(value = "delete")
    public CommonResult delete(Integer id){
        int i = studentService.delete(id);
        if (i==1){
            return new CommonResult(2000,"成功",null);
        }
        return new CommonResult(5000,"成功",null);
    }
}

7.3  service层

7.3.1 接口

package com.sfc.service;

import com.sfc.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 16:11
 */
public interface StudentService {
    //所有信息
    public List<Student> selectAll();
    //添加信息
    public int insert(Student student);

    //修改信息
    public int update(Student student);

    //删除操作
    public int delete(Integer id);
}

7.3.2  service的工厂类

package com.sfc.service.abc;

import com.sfc.dao.StudentMapper;
import com.sfc.entity.Student;
import com.sfc.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author  : sfc
 *
 * @date : 2022-06-18 16:13
 */
@Service
public class StudentServiceAbc implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override//查询所有
    public List<Student> selectAll() {
        List<Student> list = studentMapper.selectAll();
        return list;
    }

    @Override//添加
    public int insert(Student stusent) {
        int i = studentMapper.insertSelective(stusent);
        return i;
    }

    @Override
    public int update(Student student) {
        System.out.println("ssss");
        int i = studentMapper.updateByPrimaryKeySelective(student);
        return i;
    }

    @Override
    public int delete(Integer id) {
        int i = studentMapper.deleteByPrimaryKey(id);
        return i;
    }


}

7.4  dao包下的StudentMapper接口中需添加一个方法

List<Student> selectAll();

7.5  Mapper映射中同样增加对应的SQL

  <select id="selectAll" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from student
  </select>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值