新增员工信息

作者:李坤凤
本次任务完成时间:2019年6月15日
开发工具与关键技术:开发工具:VS 关键技术: 新增员工信息

一、 编写数据的存储过程语句
1、 新建存储语句,编写存储语句,新增一条数据;
在这里插入图片描述
2、定义传递参数,传递参数的类型,在存储过程中就定义好了,给参数类型赋值,
3、在服务端写服务契约,然后启动,到客户端引用服务或者更新服务;

//OperationContract(操作契约)新增账号信息数据
        [OperationContract]
        public int btn_Save_Click_InsertStaffAccountManage(int intID,string strAccounts,string strPassword,bool blEffective,string strNote)
        {
            //实例化对象数组
            SqlParameter[] mySqlParameters ={
                //定义传递参数,以及传递参数的类型
                new SqlParameter("@type",SqlDbType.NChar),
                new SqlParameter("@staff_id",SqlDbType.Int),
                new SqlParameter("@operator_accounts",SqlDbType.NChar),
                new SqlParameter("@operator_password",SqlDbType.NChar),
                new SqlParameter("@effective",SqlDbType.Bit),
                new SqlParameter("@note",SqlDbType.NChar),
            };
            //给对象赋值
            mySqlParameters[0].Value = "btn_Save_Click_InsertStaffAccountManage";
            mySqlParameters[1].Value = intID;
            mySqlParameters[2].Value = strAccounts;
            mySqlParameters[3].Value = strPassword;
            mySqlParameters[4].Value = blEffective;
            mySqlParameters[5].Value = strNote;
            int count = myDALMethod.UpdateData("UC_StaffAccountManage", mySqlParameters);
            //返回数值
            return count; }

4、在客户端这边写新增保存按钮的功能,判断新增的数据是不是唯一性,或者新增的数据重复新增,需要新增信息数据的唯一性,使用if…else语句判断新增信息数据没有填写完整点击保存,则会显示数据没有填写完整,需要填写完整才可以保存;
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 MyBatis 中新增员工信息需要进行如下步骤: 1. 创建员工信息实体类,例如: ```java public class Employee { private Integer id; private String name; private Integer age; // 省略 getter 和 setter 方法 } ``` 2. 创建 Mapper 接口,定义新增员工信息的方法,例如: ```java public interface EmployeeMapper { void addEmployee(Employee employee); } ``` 3. 创建 Mapper XML 文件,映射新增员工信息的 SQL 语句,例如: ```xml <mapper namespace="com.example.mapper.EmployeeMapper"> <insert id="addEmployee" parameterType="com.example.entity.Employee"> insert into employee(name, age) values (#{name}, #{age}) </insert> </mapper> ``` 4. 在 Spring 配置文件中配置 MyBatis 相关的 Bean,例如: ```xml <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mybatis" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath:mapper/*.xml" /> </bean> <bean id="employeeMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.example.mapper.EmployeeMapper" /> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> ``` 5. 在业务逻辑代码中调用新增员工信息的方法,例如: ```java @Autowired private EmployeeMapper employeeMapper; public void addEmployee(Employee employee) { employeeMapper.addEmployee(employee); } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值