基於SSM開發的健身俱樂部管理系統 JAVA MySQL

逐漸邁入成熟的老男人發表於2020-11-12

10105基於SSM開發的健身俱樂部管理系統

程式碼:
鏈-椄:https://pan@baidu@com/s/1wAjL3PK78Bv9866q-B6kuw (把@換成 . 就可正常訪問)
趧-紶-碼:1226
f/u枝此段-吶傛開啟baidu網盤手機App,caozuo更方便哦

技術
Spring + SpringMVC + Mybatis

工具
eclipse + tomact + mysql + jdk

功能詳情

管理員許可權會員許可權
資訊總覽我的資訊
會員列表選課列表
教練列表選擇教練
器材管理
退出系統

系統相關截圖

● 系統首頁

在這裡插入圖片描述

  • 會員頁面

在這裡插入圖片描述
package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.UserDAO;
import com.model.User;

@Service(“userService”)
public class UserServiceImp implements UserService {
@Autowired
private UserDAO userDAO;

@Override
public boolean exits(String username){
	List<User> userList = userDAO.findByUsername(username);
	if(userList.size()>0)
		return true;
	else
		return false;
}

@Override
public List<User> queryUsers(String username){
	if(username == null || "".equals(username))
		return userDAO.findAllUsers();
	else return userDAO.queryByUsername(username);
}

@Override
 public User getUser(Integer id){
		return userDAO.getUser(id);
}

@Override
@Transactional
public void save(User user){
	userDAO.save(user);
}

@Override
@Transactional
public void modifyUser(User user){
	userDAO.update(user);
}

@Override
@Transactional
public void deleteUser(Integer id){
	userDAO.delete(id);
}

}
package com.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserService;

@Component(“userAction”)
@Scope(“prototype”)
public class UserAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
@Autowired
private UserService userService;

private User user;

private String searchText;

private List<User> users;

public User getUser() {
	return user;
}
public void setUser(User user) {
	this.user = user;
}
public UserService getUserService() {
	return userService;
}
@Resource
public void setUserService(UserService userService) {
	this.userService = userService;
}

public String addUser(){
	if(userService.exits(user.getUsername())){
		return ERROR;
	}
	userService.save(user);
	return SUCCESS;
}

public String queryUser(){
	searchText = getParam("queryText");
	users = userService.queryUsers(searchText);
	return SUCCESS;
}

public String editUser(){
	try {
		Integer param = Integer.parseInt(getParam("param"));
		if(param == 0){
			Integer id = Integer.parseInt(getParam("id"));
			user = userService.getUser( id);
			return "editUser";
		}else if(param == 1){
			userService.modifyUser(user);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return SUCCESS;
}

public String deleteUser(){
	try {
		Integer param = Integer.parseInt(getParam("id"));
		userService.deleteUser(param);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return queryUser() ;
}
public String getSearchText() {
	return searchText;
}
public void setSearchText(String searchText) {
	this.searchText = searchText;
}
protected String getParam(String key){
	return ServletActionContext.getRequest().getParameter(key);
}
public List<User> getUsers() {
	return users;
}
public void setUsers(List<User> users) {
	this.users = users;
}

}

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

<!-- 用註解方法注入bean 上邊schemaLocation的三條語句順序很重要,否則報錯 -->
<context:annotation-config />
<context:component-scan base-package="com" />

<!-- 資料庫連線池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
	destroy-method="close">
	<property name="driverClassName" value="com.mysql.jdbc.Driver" />
	<property name="url" value="jdbc:mysql://localhost:3306/mydb?useUnicode=true&amp;characterEncoding=UTF-8" />
	<property name="username" value="root" />
	<property name="password" value="123456" />
</bean>

<!-- 配置sessionFactory ,資料庫配置在hibernate.cfg.xml中-->
<!--LocalSessionFactoryBean 載入bean方式 <mapping resource="com/model/User.hbm.xml"/>
    AnnotationSessionFactoryBean 載入bean方式 <mapping class="com.model.User"/> ,它主要功能是取消了hbm.xml檔案
 -->
<bean id="sessionFactory"
	class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
	<property name="dataSource" ref="dataSource" />
	<!-- 配置實體描述檔案 -->
	<property name="mappingResources">
		<list>
			<value>com/model/User.hbm.xml</value>
		</list>
	</property>
	<!--掃描com.cuangwu包下以及子包種有 @Service @Controller @Repository @Component  註解的類,一旦發現,則將其納入到spring容器中管理 
        此spring.jar必須是 Spring2.5以上版本的,因為,Spring2.5之前org.springframework.orm.hibernate3.LocalSessionFactoryBean類中,
        並沒有 packageToScan 這個屬性,只有mappingResuorces這個屬性。而packageToScan這個屬性正是對映包中的類,而mappingResuorces只是對映某個檔案。-->
	<!-- <property name="packagesToScan" > <list> <value>com.model</value> 
		</list> </property> -->
	<property name="hibernateProperties">
		<props>
			<prop key="hibernate.format_sql">true</prop>
			<prop key="hibernate.hbn2dd1.auto">update</prop>
			<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
		</props>
	</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置事務管理器 -->
<bean id="transactionManager"
	class="org.springframework.orm.hibernate3.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
	<tx:attributes>
		<tx:method name="find*" read-only="true" />
		<tx:method name="add*" propagation="REQUIRED" />
		<tx:method name="delete*" propagation="REQUIRED" /> 
        <tx:method name="update*" propagation="REQUIRED" /> 
	</tx:attributes>
</tx:advice>
<!-- aop代理設定--> 
<aop:config>
	<aop:pointcut expression="execution(public * com.service..*.*(..))"
		id="myPointcut" />
	<aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
</aop:config>

相關文章