基于SSM的模拟校园系统

开发平台:idea+mysql+jdk

使用技术:Spring SpringMVC MyBatis maven

服务器:tomcat

关键代码

<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.zyzx</groupId>
	<artifactId>dxszyzx</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<properties>
		<spring.version>4.3.7.RELEASE</spring.version>
		<mybatis.version>3.2.6</mybatis.version>
		<slf4j.version>1.7.7</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
<!--Spring 框架基本的核心工具类。Spring 其它组件要都要使用到这个包里的类,是其它组件的基本核心-->		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!--包含Web 应用开发时,用到Spring 框架时所需的核心类,包括自动载入Web Application Context 特性的类、Struts 与JSF 集成类、文件上传的支持类、Filter 类和大量工具辅助类 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!--Spring对于object/xml映射的支持,可以让JAVA与XML之间来回切换 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!--对事务注解的解析器 -->		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!-- 包含对Spring 对JDBC 数据访问进行封装的所有类。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!-- 包含Spring MVC 框架相关的所有类。包括框架的Servlets,Web MVC框架,控制器和视图支持。当然,如果你的应用使用了独立的MVC 框架,则无需这个JAR 文件里的任何类 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!--包含在应用中使用Spring 的AOP 特性时所需的类和源码级元数据支持。使用基于AOP 的Spring特性,如声明型事务管理 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
		</dependency>
<!-- Spring context的扩展支持,用于MVC方面 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.30</version>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.2.2</version>
		</dependency>
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>${log4j.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<!-- 文件上传配置 -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.9</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.8.4</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.8.4</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>2.8.4</version>
		</dependency>
		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
			<version>20160810</version>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.2.4</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>demo</finalName>
		<plugins>
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.2</version>
				<configuration>
					<verbose>true</verbose>
					<overwrite>true</overwrite>
				</configuration>
			</plugin>
		</plugins>
	</build>
	
</project>

 

@Controller
public class CenterController {

    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private WangKeMapper wangKeMapper;
    @Autowired
    private LiuYanMapper liuYanMapper;

    //记录各种值信息
    private void updateInfo(HttpSession session){
        int uid = Integer.parseInt(String.valueOf(session.getAttribute("uid")));
        User user = userMapper.selectByPrimaryKey(uid);
        session.setAttribute("ylz",user.getYuelinum());
        session.setAttribute("sjz",user.getShejiaonum());
        session.setAttribute("tlz",user.getTilinum());
        session.setAttribute("zlz",user.getZhilinum());
    }

    //首次访问,进行页面跳转,跳转到index前端页面
    @RequestMapping(value = "/",method = {RequestMethod.GET,RequestMethod.POST})
    public String index(){
        return "login";
    }
    //登陆
    @RequestMapping(value = "/login",method = {RequestMethod.GET,RequestMethod.POST})
    public String login(User user,Model model,HttpSession session){
        User user0 = userMapper.selectForLogin(user);
        if(user0==null){
            model.addAttribute("err","用户名或密码错误!!!");

            return "login";
        }
        session.setAttribute("uid",user0.getId());
        session.setAttribute("user",user0);
        updateInfo(session);
        return "index";
    }
    //注册
    @RequestMapping(value = "/re",method = {RequestMethod.GET,RequestMethod.POST})
    public String re(User user,Model model,HttpSession session){
        userMapper.insertSelective(user);
        return "login";
    }
    //修改个人信息
    @RequestMapping(value = "/updateInfo",method = {RequestMethod.GET,RequestMethod.POST})
    public String updateInfo(User user,Model model,HttpSession session){
        userMapper.updateByPrimaryKeySelective(user);
        session.setAttribute("user",user);
        return "center";
    }
   //去图书馆页面
   @RequestMapping(value = "/to_tushuguan",method = {RequestMethod.GET,RequestMethod.POST})
   public String to_tushuguan(Model model,HttpSession session){
        model.addAttribute("books",bookMapper.selectAll());
        updateInfo(session);
        return "tushuguan";
   }
    //借书
    @RequestMapping(value = "/jieshu",method = {RequestMethod.GET,RequestMethod.POST})
    public String jieshu(Model model, int[] bookids, HttpSession session){
        if (bookids==null){
            model.addAttribute("err","<script>alert('请至少选择一本书!!!');window.location.href='/to_tushuguan'</script>");
            return "tushuguan";
        }else {
            //增加阅历值
            int n = bookids.length;
            int uid = Integer.parseInt(String.valueOf(session.getAttribute("uid")));
//            int uid = 1;
            User user = new User();
            user.setId(uid);
            user.setYuelinum(userMapper.selectByPrimaryKey(uid).getYuelinum()+n);
            userMapper.updateByPrimaryKeySelective(user);
            //修改图书状态
            for(int id:bookids){
                Book book = new Book();
                book.setId(id);
                book.setB2("借出");
                bookMapper.updateByPrimaryKeySelective(book);
            }

        }
        return "redirect:/to_tushuguan";
    }
    //开始休息
    @RequestMapping(value = "/xiuxi",method = {RequestMethod.GET,RequestMethod.POST})
    public String xiuxi(Model model,HttpSession session){
        //增加体力值
        int uid = Integer.parseInt(String.valueOf(session.getAttribute("uid")));
//        int uid = 1;
        User user = new User();
        user.setId(uid);
        user.setTilinum(userMapper.selectByPrimaryKey(uid).getTilinum()+1);
        userMapper.updateByPrimaryKeySelective(user);
        model.addAttribute("message","<script>alert('已经开始休息了!!!');</script>");
        updateInfo(session);
        return "sushe";
    }
    //去教室页面
    @RequestMapping(value = "/to_jiaoshi",method = {RequestMethod.GET,RequestMethod.POST})
    public String to_jiaoshi(Model model,HttpSession session){
        model.addAttribute("wangkes",wangKeMapper.selectAll());
        updateInfo(session);
        return "jiaoshi";
    }
    //看网课增加智力值
    @ResponseBody
    @RequestMapping(value = "/wangke",method = {RequestMethod.GET,RequestMethod.POST})
    public String wangke(Model model,String id,HttpSession session){
        //增加体力值
        int uid = Integer.parseInt(String.valueOf(session.getAttribute("uid")));
//        int uid = 1;
        User user = new User();
        user.setId(uid);
        user.setZhilinum(userMapper.selectByPrimaryKey(uid).getZhilinum()+1);
        userMapper.updateByPrimaryKeySelective(user);
        updateInfo(session);
        return "success";
    }
    //去咖啡厅页面
    @RequestMapping(value = "/to_kafeiting",method = {RequestMethod.GET,RequestMethod.POST})
    public String to_kafeiting(Model model,HttpSession session){
        model.addAttribute("liuyans",liuYanMapper.selectAll());
        updateInfo(session);
        return "kafeiting";
    }
    //开始留言
    @RequestMapping(value = "/liuyan",method = {RequestMethod.GET,RequestMethod.POST})
    public String liuyan(Model model,String content,HttpSession session){
        //增加社交值
        int uid = Integer.parseInt(String.valueOf(session.getAttribute("uid")));
//        int uid = 1;
        User user = new User();
        user.setId(uid);
        user.setShejiaonum(userMapper.selectByPrimaryKey(uid).getShejiaonum()+1);
        userMapper.updateByPrimaryKeySelective(user);
        //留言
        LiuYan ly = new LiuYan();
        ly.setContent(content);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ly.setTime(sdf.format(new Date()));
        ly.setUid(uid);
        ly.setUname(userMapper.selectByPrimaryKey(uid).getName());
        liuYanMapper.insertSelective(ly);
        updateInfo(session);
        return "redirect:/to_kafeiting";
    }
    //---------------------------------------------------------------------------------------------------------------------
    //去后台管理页面
    @RequestMapping(value = "/admin",method = {RequestMethod.GET,RequestMethod.POST})
    public String admin(Model model,HttpSession session){
        //查询所有用户信息
        model.addAttribute("users",userMapper.selectAll());
        return "admin_index";
    }
    //去后台网课管理页面
    @RequestMapping(value = "/wangke_index",method = {RequestMethod.GET,RequestMethod.POST})
    public String wangke_index(Model model,HttpSession session){
        //查询所有网课信息
        model.addAttribute("wangkes",wangKeMapper.selectAll());
        return "wangke_index";
    }
    //去后台留言管理页面
    @RequestMapping(value = "/liuyan_index",method = {RequestMethod.GET,RequestMethod.POST})
    public String liuyan_index(Model model,HttpSession session){
        //查询所有留言信息
        model.addAttribute("liuyans",liuYanMapper.selectAll());
        return "liuyan_index";
    }
    //去后台图书管理页面
    @RequestMapping(value = "/book_index",method = {RequestMethod.GET,RequestMethod.POST})
    public String book_index(Model model,HttpSession session){
        //查询所有图书信息
        model.addAttribute("books",bookMapper.selectAll1());
        return "book_index";
    }
    //添加用户信息 user_add
    @RequestMapping(value = "/user_add",method = {RequestMethod.GET,RequestMethod.POST})
    public String user_add(Model model,HttpSession session,User user){
        System.out.println(user);
        userMapper.insertSelective(user);
        return "redirect:/admin";
    }
    //添加图书信息 book_add
    @RequestMapping(value = "/book_add",method = {RequestMethod.GET,RequestMethod.POST})
    public String book_add(Model model, HttpServletRequest request, Book book, MultipartFile file){

        try {
            String path = request.getServletContext().getRealPath("imgs");
            File f = new File(path,file.getOriginalFilename());
            file.transferTo(f);
            book.setB1(file.getOriginalFilename());
            book.setB2("在馆");
            bookMapper.insertSelective(book);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "redirect:/book_index";
    }
    //添加网课信息 wangke_add
    @RequestMapping(value = "/wangke_add",method = {RequestMethod.GET,RequestMethod.POST})
    public String wangke_add(Model model, HttpServletRequest request, WangKe wangke, @RequestParam("file")MultipartFile file){

        try {
            String path = request.getServletContext().getRealPath("videos");
            File f = new File(path,file.getOriginalFilename());
            file.transferTo(f);
            wangke.setName(file.getOriginalFilename());
            wangKeMapper.insertSelective(wangke);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "redirect:/wangke_index";
    }
    //去用户编辑页面
    @RequestMapping(value = "/to_user_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String to_user_update(Model model,HttpSession session,int id){
        model.addAttribute("user",userMapper.selectByPrimaryKey(id));
        return "user_update";
    }
    //用户编辑
    @RequestMapping(value = "/user_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String user_update(Model model,HttpSession session,User user){
        userMapper.updateByPrimaryKeySelective(user);
        return "redirect:/admin";
    }

    //去图书编辑页面
    @RequestMapping(value = "/to_book_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String to_book_update(Model model,HttpSession session,int id){
        model.addAttribute("book",bookMapper.selectByPrimaryKey(id));
        return "book_update";
    }
    //图书编辑
    @RequestMapping(value = "/book_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String book_update(Model model,HttpSession session,Book book){
        bookMapper.updateByPrimaryKeySelective(book);
        return "redirect:/book_index";
    }
    //去网课编辑页面
    @RequestMapping(value = "/to_wangke_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String to_wangke_update(Model model,HttpSession session,int id){
        model.addAttribute("wangke",wangKeMapper.selectByPrimaryKey(id));
        return "wangke_update";
    }
    //网课编辑
    @RequestMapping(value = "/wangke_update",method = {RequestMethod.GET,RequestMethod.POST})
    public String wangke_update(Model model,HttpSession session,WangKe wangKe){
        wangKeMapper.updateByPrimaryKeySelective(wangKe);
        return "redirect:/wangke_index";
    }

    //删除用户
    @RequestMapping(value = "/user_del",method = {RequestMethod.GET,RequestMethod.POST})
    public String user_del(Model model,HttpSession session,int id){
        userMapper.deleteByPrimaryKey(id);
        return "redirect:/admin";
    }
    //删除图书
    @RequestMapping(value = "/book_del",method = {RequestMethod.GET,RequestMethod.POST})
    public String book_del(Model model,HttpSession session,int id){
        bookMapper.deleteByPrimaryKey(id);
        return "redirect:/book_index";
    }

    //删除留言
    @RequestMapping(value = "/liuyan_del",method = {RequestMethod.GET,RequestMethod.POST})
    public String liuyan_del(Model model,HttpSession session,int id){
        liuYanMapper.deleteByPrimaryKey(id);
        return "redirect:/liuyan_index";
    }

    //删除留言
    @RequestMapping(value = "/wangke_del",method = {RequestMethod.GET,RequestMethod.POST})
    public String wangke_del(Model model,HttpSession session,int id){
        wangKeMapper.deleteByPrimaryKey(id);
        return "redirect:/wangke_index";
    }
}

 

项目下载:基于SSM的模拟校园系统

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aqiu12316

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值