日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

idea 新建ssm java ee_IDEA搭建SSM项目实现增删改查

發布時間:2024/9/27 85 豆豆
生活随笔 收集整理的這篇文章主要介紹了 idea 新建ssm java ee_IDEA搭建SSM项目实现增删改查 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先打開IDEA,File—>New—>Project創建項目

選擇左側導航欄里的Maven,勾上勾,選擇webapp

按如下圖進行填寫

創建完成后進入項目,右下角彈出的提示點擊右邊的Enable Auto-Import,自動配置

連接數據庫,我用的是Mysql數據庫,準備好有數據的數據庫表

在pom.xml里導入所需jar包:

4.0.0

war

Student-ssm

com.accp

Student-ssm

1.0-SNAPSHOT

org.aspectj

aspectjweaver

1.8.8

org.springframework

spring-webmvc

4.3.12.RELEASE

org.springframework

spring-tx

4.3.12.RELEASE

org.springframework

spring-jdbc

4.3.12.RELEASE

org.mybatis

mybatis

3.4.5

org.mybatis

mybatis-spring

1.3.1

mysql

mysql-connector-java

5.1.44

com.alibaba

druid

1.1.2

javax.servlet

jstl

1.2

javax.servlet

javax.servlet-api

3.0.1

provided

總體結構:

web.xml代碼:

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

springmvc

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml

springmvc

/

springmvc.xml代碼:

entity學生實體類代碼:

package com.accp.entity;

public class Studentinfo {

private long sid;

private String sname;

private String sgender;

private long sage;

private String saddress;

private String semail;

public long getSid() {

return sid;

}

public void setSid(long sid) {

this.sid = sid;

}

public String getSname() {

return sname;

}

public void setSname(String sname) {

this.sname = sname;

}

public String getSgender() {

return sgender;

}

public void setSgender(String sgender) {

this.sgender = sgender;

}

public long getSage() {

return sage;

}

public void setSage(long sage) {

this.sage = sage;

}

public String getSaddress() {

return saddress;

}

public void setSaddress(String saddress) {

this.saddress = saddress;

}

public String getSemail() {

return semail;

}

public void setSemail(String semail) {

this.semail = semail;

}

}

dao層StudentinfoDao代碼:

package com.accp.dao;

import com.accp.entity.Studentinfo;

import java.util.List;

public interface StudentinfoDao {

ListqueryStudent();

int addStudentinfo(Studentinfo studentinfo);

int deleteStudentinfo(Studentinfo studentinfo);

int updateStudentinfo(Studentinfo studentinfo);

Studentinfo getByStudentId(Studentinfo studentinfo);

}

resources下xml里Studentinfo.xml代碼:

select * from studentinfo;

select * from studentinfo where sid = #{sid}

insert into studentinfo value (default ,#{sname},#{sgender},#{sage},#{saddress},#{semail})

delete from studentinfo where sid = #{sid}

update studentinfo

sname = #{sname},

sgender = #{sgender},

sage = #{sage},

saddress = #{saddress},

semail = #{semail},

service層StudentinfoService代碼:

package com.accp.service;

import com.accp.entity.Studentinfo;

import java.util.List;

public interface StudentinfoService {

ListqueryStudent();

int addStudentinfo(Studentinfo studentinfo);

int deleteStudentinfo(Studentinfo studentinfo);

int updateStudentinfo(Studentinfo studentinfo);

Studentinfo getByStudentId(Studentinfo studentinfo);

}

service層Impl實現類StudentinfoServiceImpl代碼:

package com.accp.service.impl;

import com.accp.dao.StudentinfoDao;

import com.accp.entity.Studentinfo;

import com.accp.service.StudentinfoService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

@Service

public class StudentinfoServiceImpl implements StudentinfoService {

@Resource

private StudentinfoDao studentinfoDao;

public ListqueryStudent() {

return studentinfoDao.queryStudent();

}

public int addStudentinfo(Studentinfo studentinfo) {

return studentinfoDao.addStudentinfo(studentinfo);

}

public int deleteStudentinfo(Studentinfo studentinfo) {

return studentinfoDao.deleteStudentinfo(studentinfo);

}

public int updateStudentinfo(Studentinfo studentinfo) {

return studentinfoDao.updateStudentinfo(studentinfo);

}

public Studentinfo getByStudentId(Studentinfo studentinfo) {

return studentinfoDao.getByStudentId(studentinfo);

}

}

controller控制層StudentinfoController代碼:

package com.accp.controller;

import com.accp.entity.Studentinfo;

import com.accp.service.StudentinfoService;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller

public class StudentinfoController {

@Resource

private StudentinfoService studentinfoService;

@RequestMapping("/showList")

public String showList(Model model){

model.addAttribute("students",studentinfoService.queryStudent());

return "index";

}

@RequestMapping("/JumpAdd")

public String jumpAdd(){

return "add";

}

@RequestMapping("/AddList")

public String addList(Studentinfo studentinfo){

studentinfoService.addStudentinfo(studentinfo);

return "redirect:showList";

}

@RequestMapping("/DeleteS")

public String deleteS(Studentinfo studentinfo){

studentinfoService.deleteStudentinfo(studentinfo);

return "redirect:showList";

}

@RequestMapping("/JumpUpdate")

public String jumpUpdate(Studentinfo studentinfo,Model model){

model.addAttribute("stu",studentinfoService.getByStudentId(studentinfo));

return "update";

}

@RequestMapping("/UpdateS")

public String updateS(Studentinfo studentinfo){

studentinfoService.updateStudentinfo(studentinfo);

return "redirect:showList";

}

}

jsp頁面代碼:

顯示頁面(包含刪除操作):

Title

增加

編號

姓名

性別

年齡

地址

email

操作

${stu.sid}

${stu.sname}

${stu.sgender}

${stu.sage}

${stu.saddress}

${stu.semail}

添加頁面:

添加

姓名:

性別:

年齡:

地址:

郵箱:

修改頁面:

修改

姓名:

性別:

年齡:

地址:

郵箱:

顯示效果:

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的idea 新建ssm java ee_IDEA搭建SSM项目实现增删改查的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。