【JavaWeb】将普通项目变成ssm项目 02

【JavaWeb】将普通项目变成ssm项目 02,第1张

目标
  • 实现用户类的所有方法

User类的一些 *** 作方法
package com.stuos.dao;

import java.util.List;

import com.stuos.po.User;

/*
 *User类的一些 *** 作方法
 * 1.保存对象到数据库
 * 2.更新对象的数据库内容
 * 3.按照主键找到对象
 * 4.获得整个表
 * 5.根据主键删除对象
 * 6.保存或更新对象
 * 7.找到所有秘书对象
 * 8.找到所有辅导员对象
 * 9.找到所有学生对象
 * 10.找到所有专业人员对象
 * 11.找到所有老师对象
 * 12.查找某身份的所有对象
 * */
public interface UserDao {
	public void save(User user);
	public void update(User user);
	public User findById(String userAcc);
	public List<User> getAll();
	public void delete(String userAcc);
	public void saveOrupdate(User user);
	public List<User> getAllSecr();
	public List<User> getAllInst();
	public List<User> getAllStu();
	public List<User> getAllProf();
	public List<User> getAllTea();
	public List<User> getAllById(String Id);
}

1.保存对象到数据库

	<insert id="save" parameterType="User">
		insert into
		tb_user(userId,userAcc,userPwd,userName,userAge,userSex)
		values(#{userId},#{userAcc},#{userPwd},#{userName},#{userAge},#{userSex})
	insert>
2.更新对象的数据库内容

	<update id="update" parameterType="User">
		update tb_user set userId =
		#{userId},userPwd = #{userPwd},userName = #{userName},userAge =
		#{userAge},userSex = #{userSex} where userAcc = #{userAcc}
	update>
3.按照主键找到对象

	<select id="findById" parameterType="string" resultType="User">
		select *
		from tb_user where userAcc = #{userAcc}
	select>
4.获得整个表

	<select id="getAll" resultType="User">
		select * from tb_user
	select>
5.根据主键删除对象

	<delete id="delete" parameterType="string">
		delete from tb_user where
		userAcc = #{userAcc}
	delete>
6.保存或更新对象

	<insert id="saveOrupdate" parameterType="User">
		replace into
		tb_user(userId,userAcc,userPwd,userName,userAge,userSex)
		values(#{userId},#{userAcc},#{userPwd},#{userName},#{userAge},#{userSex})
	insert>
7.找到所有秘书对象

	<select id="getAllSecr" resultType="User">
		select * from tb_user u where
		find_in_set('6',u.userId)>0
	select>
8.找到所有辅导员对象

	<select id="getAllInst" resultType="User">
		select * from tb_user u where
		find_in_set('5',u.userId)>0
	select>
9.找到所有学生对象

	<select id="getAllStu" resultType="User">
		select * from tb_user u where
		find_in_set('7',u.userId)>0
	select>
10.找到所有专业人员对象

	<select id="getAllProf" resultType="User">
		select * from tb_user u where
		find_in_set('2',u.userId)>0 or find_in_set('3',u.userId)>0 or
		find_in_set('4',u.userId)>0
	select>
11.找到所有老师对象

	<select id="getAllTea" resultType="User">
		select * from tb_user u where
		find_in_set('4',u.userId)>0
	select>
12.查找某身份的所有对象

	<select id="getAllById" parameterType="string" resultType="User">
		select * from tb_user u where
		find_in_set('#{Id}',u.userId)>0
	select>

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/917357.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存