Spring+SpringMVC+MyBatis明日方舟版人员信息管理系统后端代码(前后端交互+SSM框架 管理员登录 游客登录 普通用户登录 人员的增删改查 信息更新 图片上传 分页查询)
文章目录
配置信息
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--开启注解扫描-->
<context:component-scan base-package="org.island">
<!--配置要忽略的注解扫描,要扫描的是service和dao层的注解,要忽略web层注解,因为web层让SpringMVC框架
去管理 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!--配置连接池,我这里用的c3p0,也可以用其他的连接池-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3309/luodedao" />
<property name="username" value="root" />
<property name="password" value="131427" />
</bean>
<!--配置SqlSession的工厂 注入连接池-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="dataSource"></property>
<!--配置实体类的别名扫描 可选-->
<property name="typeAliasesPackage" value="org.island.bean"/>
</bean>
<!--配置AccountDao 所在的包-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.island.dao"></property>
</bean>
<!--配置事务管理器,传入连接池-->
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--配置事务通知-->
<tx:advice transaction-manager="transactionManager" id="tx">
<tx:attributes>
<!--以find开头的方法,用于指定事务是否只读。只有查询方法才能设置为true-->
<tx:method name="find*" read-only="true"/>
<!--isolation用于指定事务的隔离级别。默认值是DEFAULT * 表示所有方法-->
<tx:method name="*" isolation="DEFAULT"></tx:method>
</tx:attributes>
</tx:advice>
<!-- 配置AOP切面产生代理 -->
<aop:config>
<aop:advisor advice-ref="tx" pointcut="execution(public * org.island.dao.*.*(..))"/>
</aop:config>
</beans>
springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--只扫描Controller注解,别的注解不扫描-->
<context:component-scan base-package="org.island">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- <!–配置视图解析器–>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">
<!– JSP文件所在的目录 –>
<property name="prefix" value="/WEB-INF/main/"></property>
<!– 文件的后缀名 –>
<property name="suffix" value=".jsp"></property>
</bean>-->
<!-- 设置静态资源不过滤 -->
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/main/" mapping="/main/**"/>
<mvc:resources location="/WEB-INF/main/" mapping="/WEB-INF/main/**"/>
<!-- 开启对SpringMVC注解的支持 -->
<mvc:annotation-driven/>
</beans>
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置properties-->
<!-- <properties resource="jdbcConfig.properties">
</properties>-->
<typeAliases>
<package name="org.san.bean"/>
</typeAliases>
<!--配置环境-->
<environments default="mysql">
<!-- 配置mysql的环境-->
<environment id="mysql">
<!-- 配置事务 -->
<transactionManager type="JDBC"/>
<!--配置连接池-->
<!-- <dataSource type="POOLED">
<property name="driver" value="${jdbc.DriverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>-->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3309/luodedao" />
<property name="username" value="root" />
<property name="password" value="131427" />
</dataSource>
</environment>
</environments>
<!-- 配置映射文件的位置 -->
<mappers>
<package name="org.island.dao"/>
</mappers>
</configuration>
dao接口代码
博士dao
package org.island.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.island.bean.Doctor;
import org.island.bean.GanYuan;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository(value = "doctorDao")
public interface IDoctorDao {
@Select("Select * from doctor")
List<Doctor> findAll();
@Update("update doctor set password=#{password} where manager=#{manager}")
void update(@Param("password") String password,@Param("manager") String manager);
}
用户dao
package org.island.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.island.bean.User;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository(value = "iUserDao")
public interface IUserDao {
@Select("select * from user")
List<User> findAll();
@Insert("insert into user(username,password) values(#{username},#{password})")
void saveUser(User user);
@Update("update user set password=#{password} where username=#{username}")
void update(@Param("password") String password,@Param("username") String username);
}
干员信息dao
package org.island.dao;
import org.apache.ibatis.annotations.*;
import org.island.bean.GanYuan;
import java.util.List;
public interface IGanYuanDao {
@Select("select * from ganyuan")
List<GanYuan> findAll();
@Select("select * from ganyuan where gyname like #{gyname}")
List<GanYuan> findMo(@Param("gyname") String name);
@Select("select * from ganyuan limit #{first},#{last}")
List<GanYuan> findLimit(@Param("first") int first,@Param("last") int last);
@Select("select * from GanYuan limit #{p1},#{p2}")
List<GanYuan> limit(int p1,int p2);
@Insert("insert into ganyuan(gyname,gyinfected,gyjob,gycompany,gyrace,gydescription) values(#{gyname},#{gyinfected},#{gyjob},#{gycompany},#{gyrace},#{gydescription})")
void add(GanYuan ganyuan);
@Delete("delete from ganyuan where gyid=#{gyid}")
void del(int id);
@Update("update ganyuan set gyname=#{gyname},gyinfected=#{gyinfected},gyjob=#{gyjob},gycompany=#{gycompany},gyrace=#{gyrace},gydescription=#{gydescription} where gyid=#{gyid}")
void update(GanYuan ganyuan);
}
Utils代码
文件
package org.island.Utils;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class FileType {
public final static Map<String, String> FILE_TYPE_MAP = new HashMap<String, String>();
private FileType() {
}
static {
getAllFileType(); //初始化文件类型信息
}
/**
* Discription:[getAllFileType,常见文件头信息]
*/
private static void getAllFileType() {
FILE_TYPE_MAP.put("ffd8ffe000104a464946", "jpg"); //JPEG (jpg)
FILE_TYPE_MAP.put("89504e470d0a1a0a0000", "png"); //PNG (png)
FILE_TYPE_MAP.put("47494638396126026f01", "gif"); //GIF (gif)
FILE_TYPE_MAP.put("49492a00227105008037", "tif"); //TIFF (tif)
FILE_TYPE_MAP.put("424d228c010000000000", "bmp"); //16色位图(bmp)
FILE_TYPE_MAP.put("424d8240090000000000", "bmp"); //24位位图(bmp)
FILE_TYPE_MAP.put("424d8e1b030000000000", "bmp"); //256色位图(bmp)
FILE_TYPE_MAP.put("41433130313500000000", "dwg"); //CAD (dwg)
FILE_TYPE_MAP.put("3c21444f435459504520", "html"); //HTML (html)
FILE_TYPE_MAP.put("3c21646f637479706520", "htm"); //HTM (htm)
FILE_TYPE_MAP.put("48544d4c207b0d0a0942", "css"); //css
FILE_TYPE_MAP.put("696b2e71623d696b2e71", "js"); //js
FILE_TYPE_MAP.put("7b5c727466315c616e73", "rtf"); //Rich Text Format (rtf)
FILE_TYPE_MAP.put("38425053000100000000", "psd"); //Photoshop (psd)
FILE_TYPE_MAP.put("46726f6d3a203d3f6762", "eml"); //Email [Outlook Express 6] (eml)
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "doc"); //MS Excel 注意:word、msi 和 excel的文件头一样
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "vsd"); //Visio 绘图
FILE_TYPE_MAP.put("5374616E64617264204A", "mdb"); //MS Access (mdb)
FILE_TYPE_MAP.put("252150532D41646F6265", "ps");
FILE_TYPE_MAP.put("255044462d312e350d0a", "pdf"); //Adobe Acrobat (pdf)
FILE_TYPE_MAP.put("2e524d46000000120001", "rmvb"); //rmvb/rm相同
FILE_TYPE_MAP.put("464c5601050000000900", "flv"); //flv与f4v相同
FILE_TYPE_MAP.put("00000020667479706d70", "mp4");
FILE_TYPE_MAP.put("49443303000000002176", "mp3");
FILE_TYPE_MAP.put("000001ba210001000180", "mpg"); //
FILE_TYPE_MAP.put("3026b2758e66cf11a6d9", "wmv"); //wmv与asf相同
FILE_TYPE_MAP.put("52494646e27807005741", "wav"); //Wave (wav)
FILE_TYPE_MAP.put("52494646d07d60074156", "avi");
FILE_TYPE_MAP.put("4d546864000000060001", "mid"); //MIDI (mid)
FILE_TYPE_MAP.put("504b0304140000000800", "zip");
FILE_TYPE_MAP.put("526172211a0700cf9073", "rar");
FILE_TYPE_MAP.put("235468697320636f6e66", "ini");
FILE_TYPE_MAP.put("504b03040a0000000000", "jar");
FILE_TYPE_MAP.put("4d5a9000030000000400", "exe");//可执行文件
FILE_TYPE_MAP.put("3c25402070616765206c", "jsp");//jsp文件
FILE_TYPE_MAP.put("4d616e69666573742d56", "mf");//MF文件
FILE_TYPE_MAP.put("3c3f786d6c2076657273", "xml");//xml文件
FILE_TYPE_MAP.put("494e5345525420494e54", "sql");//xml文件
FILE_TYPE_MAP.put("7061636b616765207765", "java");//java文件
FILE_TYPE_MAP.put("406563686f206f66660d", "bat");//bat文件
FILE_TYPE_MAP.put("1f8b0800000000000000", "gz");//gz文件
FILE_TYPE_MAP.put("6c6f67346a2e726f6f74", "properties");//bat文件
FILE_TYPE_MAP.put("cafebabe0000002e0041", "class");//bat文件
FILE_TYPE_MAP.put("49545346030000006000", "chm");//bat文件
FILE_TYPE_MAP.put("04000000010000001300", "mxp");//bat文件
FILE_TYPE_MAP.put("504b0304140006000800", "docx");//docx文件
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "wps");//WPS文字wps、表格et、演示dps都是一样的
FILE_TYPE_MAP.put("6431303a637265617465", "torrent");
FILE_TYPE_MAP.put("6D6F6F76", "mov"); //Quicktime (mov)
FILE_TYPE_MAP.put("FF575043", "wpd"); //WordPerfect (wpd)
FILE_TYPE_MAP.put("CFAD12FEC5FD746F", "dbx"); //Outlook Express (dbx)
FILE_TYPE_MAP.put("2142444E", "pst"); //Outlook (pst)
FILE_TYPE_MAP.put("AC9EBD8F", "qdf"); //Quicken (qdf)
FILE_TYPE_MAP.put("E3828596", "pwl"); //Windows Password (pwl)
FILE_TYPE_MAP.put("2E7261FD", "ram"); //Real Audio (ram)
}
/**
* 得到上传文件的文件头
*
* @param src
* @return
*/
public static String bytesToHexString(byte[] src) {
StringBuilder stringBuilder = new StringBuilder();
if (src == null || src.length <= 0) {
return null;
}
for (int i = 0; i < src.length; i++) {
int v = src[i] & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return stringBuilder.toString();
}
/**
* 根据制定文件的文件头判断其文件类型
*
* @param filePaht
* @return
*/
public static String getFileType(String filePaht) {
String res = null;
try {
FileInputStream is = new FileInputStream(filePaht);
byte[] b = new byte[10];
is.read(b, 0, b.length);
String fileCode = bytesToHexString(b);
//这种方法在字典的头代码不够位数的时候可以用但是速度相对慢一点
Iterator<String> keyIter = FILE_TYPE_MAP.keySet().iterator();
while (keyIter.hasNext()) {
String key = keyIter.next();
if (key.toLowerCase().startsWith(fileCode.toLowerCase()) || fileCode.toLowerCase().startsWith(key.toLowerCase())) {
res = FILE_TYPE_MAP.get(key);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public static void main(String[] args) throws Exception {
String type = getFileType("D:\\桌面图标\\首页.png");
System.out.println(type);
}
}
连接sqlsession
package org.island.Utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
public class Lian {
public static SqlSession getDao() {
InputStream in = null;
try {
in = Resources.getResourceAsStream("SqlMapConfig.xml");
} catch (IOException e) {
e.printStackTrace();
}
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
SqlSession sqlSession = factory.openSession();
return sqlSession;
}
}
UUID
package org.island.Utils;
import java.util.UUID;
public class UUIDUtils {
public static String getUUID() {
UUID uuid = UUID.randomUUID();
String str = uuid.toString();
String s = str.replaceAll("-", "");
//System.out.println(s);
return s;
}
}
验证码
package org.island.Utils;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
public class VerifyCode {
public static String drawRandomText(int width, int height, BufferedImage verifyImg) {
Graphics2D graphics = (Graphics2D) verifyImg.getGraphics();
graphics.setColor(Color.gray);//设置画笔颜色-验证码背景色
graphics.fillRect(0, 0, width, height);//填充背景
graphics.setFont(new Font("微软雅黑", Font.BOLD, 40));
//数字和字母的组合
String baseNumLetter = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
StringBuffer sBuffer = new StringBuffer();
int x = 10; //旋转原点的 x 坐标
String ch = "";
Random random = new Random();
for (int i = 0; i < 4; i++) {
graphics.setColor(getRandomColor());
//设置字体旋转角度
int degree = random.nextInt() % 30; //角度小于30度
int dot = random.nextInt(baseNumLetter.length());
ch = baseNumLetter.charAt(dot) + "";
sBuffer.append(ch);
//正向旋转
graphics.rotate(degree * Math.PI / 180, x, 45);
graphics.drawString(ch, x, 45);
//反向旋转
graphics.rotate(-degree * Math.PI / 180, x, 45);
x += 48;
}
//画干扰线
for (int i = 0; i < 6; i++) {
// 设置随机颜色
graphics.setColor(getRandomColor());
// 随机画线
graphics.drawLine(random.nextInt(width), random.nextInt(height),
random.nextInt(width), random.nextInt(height));
}
//添加噪点
for (int i = 0; i < 30; i++) {
int x1 = random.nextInt(width);
int y1 = random.nextInt(height);
graphics.setColor(getRandomColor());
graphics.fillRect(x1, y1, 2, 2);
}
return sBuffer.toString();
}
/**
* 随机取色
*/
private static Color getRandomColor() {
Random ran = new Random();
Color color = new Color(ran.nextInt(256),
ran.nextInt(256), ran.nextInt(256));
return color;
}
}
实体类
博士
package org.island.bean;
import java.io.Serializable;
public class Doctor implements Serializable {
private String manager;
private String password;
public Doctor() {
}
public Doctor(String manager, String password) {
this.manager = manager;
this.password = password;
}
@Override
public String toString() {
return "Doctor{" +
"manager='" + manager + '\'' +
", password='" + password + '\'' +
'}';
}
public String getManager() {
return manager;
}
public void setManager(String manager) {
this.manager = manager;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
用户
package org.island.bean;
import java.io.Serializable;
public class User implements Serializable {
private int id;
private String username;
private String password;
/*private static final long serialVersionUID = 7355810572012650248L;*/
public User() {
}
public User(int id, String username, String password) {
this.id = id;
this.username = username;
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
干员
package org.island.bean;
import java.io.Serializable;
public class GanYuan implements Serializable {
private int gyid;
private String gyname;
private String gyinfected;
private String gyjob;
private String gycompany;
private String gyrace;
private String gydescription;
public GanYuan() {
}
public GanYuan(int gyid, String gyname, String gyinfected, String gyjob, String gycompany, String gyrace, String gydescription) {
this.gyid = gyid;
this.gyname = gyname;
this.gyinfected = gyinfected;
this.gyjob = gyjob;
this.gycompany = gycompany;
this.gyrace = gyrace;
this.gydescription = gydescription;
}
@Override
public String toString() {
return "GanYuan{" +
"gyid='" + gyid + '\'' +
", gyname='" + gyname + '\'' +
", gyinfected='" + gyinfected + '\'' +
", gyjob='" + gyjob + '\'' +
", gycompany='" + gycompany + '\'' +
", gyrace='" + gyrace + '\'' +
", gydescription='" + gydescription + '\'' +
'}';
}
public int getGyid() {
return gyid;
}
public void setGyid(int gyid) {
this.gyid = gyid;
}
public String getGyname() {
return gyname;
}
public void setGyname(String gyname) {
this.gyname = gyname;
}
public String getGyinfected() {
return gyinfected;
}
public void setGyinfected(String gyinfected) {
this.gyinfected = gyinfected;
}
public String getGyjob() {
return gyjob;
}
public void setGyjob(String gyjob) {
this.gyjob = gyjob;
}
public String getGycompany() {
return gycompany;
}
public void setGycompany(String gycompany) {
this.gycompany = gycompany;
}
public String getGyrace() {
return gyrace;
}
public void setGyrace(String gyrace) {
this.gyrace = gyrace;
}
public String getGydescription() {
return gydescription;
}
public void setGydescription(String gydescription) {
this.gydescription = gydescription;
}
}
controller层
添加干员
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/add")
public class AddController {
@RequestMapping("/add_gan")
public void checkName(GanYuan g,HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
System.out.println(g);
ganyuan.add(g);
sqlSession.commit();
sqlSession.close();
try {
response.getWriter().write("add_success");
} catch (IOException e) {
e.printStackTrace();
}
/* try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
*/
}
@RequestMapping("/jump")
public void main(HttpServletRequest request, HttpServletResponse response){
try {
System.out.println("测试代码");
request.getRequestDispatcher("WEB-INF/main/error.jsp").forward(request, response);
System.out.println("测试代码");
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
修改密码
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.Doctor;
import org.island.bean.GanYuan;
import org.island.dao.IDoctorDao;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/change")
public class ChangeController {
@RequestMapping("/change_password")
public void checkName(String manager,String password,String newpassword, HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IDoctorDao doctor = sqlSession.getMapper(IDoctorDao.class);
List<Doctor> list = doctor.findAll();
System.out.println(manager);
System.out.println(password);
System.out.println(newpassword);
for (Doctor user : list) {
System.out.println(user);
if (manager.equals(user.getManager())){
if (password.equals(user.getPassword()))
{
doctor.update(newpassword,manager);
try {
response.getWriter().write("change_success");
} catch (IOException e) {
e.printStackTrace();
}
}else {
try {
response.getWriter().write("change_wrong");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
sqlSession.commit();
sqlSession.close();
}
@RequestMapping("/jump")
public void main(HttpServletRequest request, HttpServletResponse response){
try {
System.out.println("测试代码");
request.getRequestDispatcher("WEB-INF/main/error.jsp").forward(request, response);
System.out.println("测试代码");
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
修改用户密码
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.Doctor;
import org.island.bean.User;
import org.island.dao.IDoctorDao;
import org.island.dao.IUserDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/changeUser")
public class ChangeUserController {
@RequestMapping("/changeUser_password")
public void checkName(String username,String password,String newpassword, HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IUserDao userDao = sqlSession.getMapper(IUserDao.class);
List<User> list = userDao.findAll();
System.out.println(username);
System.out.println(password);
System.out.println(newpassword);
for (User user : list) {
System.out.println(user);
if (username.equals(user.getUsername())){
if (password.equals(user.getPassword()))
{
userDao.update(newpassword,username);
try {
response.getWriter().write("changeUser_success");
} catch (IOException e) {
e.printStackTrace();
}
}else {
try {
response.getWriter().write("change_wrong");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
sqlSession.commit();
sqlSession.close();
}
@RequestMapping("/jump")
public void main(HttpServletRequest request, HttpServletResponse response){
try {
System.out.println("测试代码");
request.getRequestDispatcher("WEB-INF/main/error.jsp").forward(request, response);
System.out.println("测试代码");
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
删除干员信息
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
@RequestMapping("/delete")
public class DeleteController {
@RequestMapping("/delete_gan")
public void checkName(String gyid,HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
System.out.println(gyid);
//ganyuan.add(g);
System.out.println(gyid);
Integer integer = Integer.valueOf(gyid);
System.out.println(integer);
ganyuan.del(integer);
sqlSession.commit();
sqlSession.close();
try {
response.getWriter().write("delete_success");
} catch (IOException e) {
e.printStackTrace();
}
}
}
删除页面信息控制
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/dfind")
public class DeleteFindController {
@RequestMapping("/dfind_gan")
public void checkName(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
String gyname = request.getParameter("gyname");
System.out.println(gyname);
List<GanYuan> list = ganyuan.findMo("%"+gyname+"%");
HttpSession session = request.getSession();
session.setAttribute("total_account", list.size());
session.setAttribute("now_page", 1);
sqlSession.commit();
sqlSession.close();
try {
request.getRequestDispatcher("/main/delete.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/dfind_limit")
public void find(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
// int now = Integer.parseInt(now_page);
// int now = Integer.parseInt(request.getParameter("now_page"));
int now = 0;
int max = (int) session.getAttribute("total_account");
int sp=max%3;
List<GanYuan> list = null;
list = ganyuan.findLimit(0, 3);
System.out.println(now);
session.setAttribute("now_page", 1);
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
try {
request.getRequestDispatcher("/main/delete.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/dfind_limit_p")
public void findp(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
int now = (int) session.getAttribute("now_page") - 1;
int max = (int) session.getAttribute("total_account");
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
List<GanYuan> list = null;
if (now > 0) {
if ((now * 3) < max) {
list = ganyuan.findLimit((now - 1) * 3,3);
System.out.println(now);
} else {
list = ganyuan.findLimit((maxpage-1) * 3, sp);
System.out.println(now);
}
session.setAttribute("now_page", now);
} else {
list = ganyuan.findLimit(0, 3);
session.setAttribute("now_page", 1);
}
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
// session.setAttribute("total_account", list.size());
try {
request.getRequestDispatcher("/main/delete.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/dfind_limit_l")
public void findl(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
// int now = Integer.parseInt(now_page);
// int now = Integer.parseInt(request.getParameter("now_page"));
int now = (int) session.getAttribute("now_page") + 1;
int max = (int) session.getAttribute("total_account");
System.out.println(max);
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
System.out.println(maxpage);
System.out.println(now);
List<GanYuan> list = null;
if (now <=maxpage) {
list = ganyuan.findLimit((now - 1) * 3, 3);
System.out.println((now - 1) * 3);
System.out.println(now * 3);
System.out.println(11111111);
session.setAttribute("now_page", now);
} else {
System.out.println(222222);
list = ganyuan.findLimit((maxpage-1) * 3,(max-((maxpage-1) * 3)));
session.setAttribute("now_page", maxpage);
}
for (GanYuan ganYuan : list) {
System.out.println(ganYuan);
}
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
// session.setAttribute("total_account", list.size());
try {
request.getRequestDispatcher("/main/delete.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/dfind_limit_z")
public void findz(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
int max = (int) session.getAttribute("total_account");
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
List<GanYuan> list = ganyuan.findLimit((maxpage - 1) * 3, (max - ((maxpage - 1) * 3)));
session.setAttribute("now_page", maxpage);
session.setAttribute("list", list);
try {
request.getRequestDispatcher("/main/delete.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
查询干员信息
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/find")
public class FindController {
@RequestMapping(value = "/find_gan",method = RequestMethod.POST)
@ResponseBody
public void checkName(String gyname,HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
List<GanYuan> list = ganyuan.findMo("%"+gyname+"%");
HttpSession session = request.getSession();
session.setAttribute("total_account", list.size());
session.setAttribute("now_page", 1);
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/find_limit")
public void find(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
// int now = Integer.parseInt(now_page);
// int now = Integer.parseInt(request.getParameter("now_page"));
int now = 0;
int max = (int) session.getAttribute("total_account");
int sp=max%3;
List<GanYuan> list = null;
list = ganyuan.findLimit(0, 3);
System.out.println(now);
session.setAttribute("now_page", 1);
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/find_limit_p")
public void findp(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
int now = (int) session.getAttribute("now_page") - 1;
int max = (int) session.getAttribute("total_account");
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
List<GanYuan> list = null;
if (now > 0) {
if ((now * 3) < max) {
list = ganyuan.findLimit((now - 1) * 3,3);
System.out.println(now);
} else {
list = ganyuan.findLimit((maxpage-1) * 3, sp);
System.out.println(now);
}
session.setAttribute("now_page", now);
} else {
list = ganyuan.findLimit(0, 3);
session.setAttribute("now_page", 1);
}
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
// session.setAttribute("total_account", list.size());
try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/find_limit_l")
public void findl(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
// int now = Integer.parseInt(now_page);
// int now = Integer.parseInt(request.getParameter("now_page"));
int now = (int) session.getAttribute("now_page") + 1;
int max = (int) session.getAttribute("total_account");
System.out.println(max);
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
System.out.println(maxpage);
System.out.println(now);
List<GanYuan> list = null;
if (now <=maxpage) {
list = ganyuan.findLimit((now - 1) * 3, 3);
System.out.println((now - 1) * 3);
System.out.println(now * 3);
System.out.println(11111111);
session.setAttribute("now_page", now);
} else {
System.out.println(222222);
list = ganyuan.findLimit((maxpage-1) * 3,(max-((maxpage-1) * 3)));
session.setAttribute("now_page", maxpage);
}
for (GanYuan ganYuan : list) {
System.out.println(ganYuan);
}
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
// session.setAttribute("total_account", list.size());
try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/find_limit_z")
public void findz(HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
int max = (int) session.getAttribute("total_account");
int maxpage = 0;
int sp=max%3;
if (max % 3 == 0) {
maxpage = (max / 3);
} else {
maxpage = (max / 3) + 1;
}
List<GanYuan> list = ganyuan.findLimit((maxpage - 1) * 3, (max - ((maxpage - 1) * 3)));
session.setAttribute("now_page", maxpage);
session.setAttribute("list", list);
try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
博士登陆
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.Doctor;
import org.island.dao.IDoctorDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/checkName")
public void checkName(String manager, String password, HttpServletRequest request, HttpServletResponse response) {
SqlSession sqlSession = Lian.getDao();
IDoctorDao doctor = sqlSession.getMapper(IDoctorDao.class);
List<Doctor> list = doctor.findAll();
HttpSession session = request.getSession();
session.setAttribute("manage_name", manager);
System.out.println(manager);
System.out.println(password);
/* for (Doctor user : list) {
System.out.println(user);
if (manager.equals(user.getManager())&&password.equals(user.getPassword())){
try {
response.getWriter().write("success");
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
boolean flag = false;
String paw = "";
for (Doctor user : list) {
System.out.println(user);
if (manager.equals(user.getManager())) {
flag = true;
paw= user.getPassword();
}
}
if (flag) {
if (paw.equals(password)) {
try {
response.getWriter().write("success");
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
response.getWriter().write("error");
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
try {
response.getWriter().write("already");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
主页面展示
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.Doctor;
import org.island.bean.GanYuan;
import org.island.dao.IDoctorDao;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/main")
public class MainController {
@RequestMapping("/show")
public void checkMain(HttpServletResponse response) throws IOException {
response.getWriter().write("show_show");
}
@RequestMapping("/search")
public void checkSearch(HttpServletRequest request,HttpServletResponse response) throws IOException {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
List<GanYuan> list = ganyuan.findAll();
HttpSession session = request.getSession();
session.setAttribute("total_account", list.size());
session.setAttribute("now_page",0);
response.getWriter().write("show_search");
}
@RequestMapping("/add")
public void checkAdd(HttpServletResponse response) throws IOException {
response.getWriter().write("show_add");
}
@RequestMapping("/delete")
public void checkDelete(HttpServletRequest request,HttpServletResponse response) throws IOException {
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
HttpSession session = request.getSession();
List<GanYuan> t = ganyuan.findAll();
session.setAttribute("total_account", t.size());
int now = 0;
int max = (int) session.getAttribute("total_account");
int sp=max%3;
List<GanYuan> list = null;
list = ganyuan.findLimit(0, 3);
System.out.println(now);
session.setAttribute("now_page", 1);
session.setAttribute("list", list);
sqlSession.commit();
sqlSession.close();
response.getWriter().write("show_delete");
}
@RequestMapping("/update")
public void checkUpdate(HttpServletResponse response) throws IOException {
response.getWriter().write("show_update");
}
@RequestMapping("/change")
public void checkChange(HttpServletResponse response) throws IOException {
response.getWriter().write("show_change");
}
@RequestMapping("/photo")
public void checkPhoto(HttpServletResponse response) throws IOException {
response.getWriter().write("show_photo");
}
}
图片上传
package org.island.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.island.Utils.UUIDUtils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/pic")
public class PictureController {
@RequestMapping("/imag")
public void checkMain(HttpServletRequest request, HttpServletResponse response) throws IOException {
String msg = "{\"pictureIsRight\":\"no\"}";
try {
request.setCharacterEncoding("utf-8");
//设置响应的类型为JSON对象
response.setContentType("application/json;charset=utf-8");
//调用方法判断该文件是否为合法的文件
DiskFileItemFactory df = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(df);
List<FileItem> list = upload.parseRequest(request);
for (FileItem fileItem : list) {
//获取到表单中的文件项
if (!fileItem.isFormField()) {
//要保存的文件的路径
String realPath = request.getServletContext().getRealPath("/upload");
File file = new File(realPath);
//创建出该路径
if (!file.exists()) {
file.mkdirs();
}
//获取上传来的文件名
String fileName = UUIDUtils.getUUID() + fileItem.getName();
//保存传上来的文件
File myPicture = new File(file, fileName);
if (!myPicture.exists()) {
//创建该文件
myPicture.createNewFile();
}
//将文件写进去
fileItem.write(myPicture);
//System.out.println("上传来的文件保存在:" + myPicture.getAbsolutePath());
// flag = userService.pictureLegal(myPicture);
}
}
/* if (flag) {
msg = "{\"pictureIsRight\":\"yes\"}";
}
*/
} catch (Exception e) {
e.printStackTrace();
}
response.getWriter().write(msg);
}
}
注册干员
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.bean.User;
import org.island.dao.IGanYuanDao;
import org.island.dao.IUserDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/register")
public class RegisterController {
@RequestMapping("/add_user")
public void checkName(User g, HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IUserDao userDao = sqlSession.getMapper(IUserDao.class);
List<User> all = userDao.findAll();
boolean flag=true;
for (User user : all) {
if(user.getUsername().equals(g.getUsername())){
flag=false;
}
}
if (flag) {
userDao.saveUser(g);
sqlSession.commit();
sqlSession.close();
try {
response.getWriter().write("adduser_success");
} catch (IOException e) {
e.printStackTrace();
}
}else {
try {
response.getWriter().write("adduser_file");
} catch (IOException e) {
e.printStackTrace();
}
}
/* try {
request.getRequestDispatcher("/main/search.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
*/
}
@RequestMapping("/jump")
public void main(HttpServletRequest request, HttpServletResponse response){
try {
System.out.println("测试代码");
request.getRequestDispatcher("WEB-INF/main/error.jsp").forward(request, response);
System.out.println("测试代码");
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
验证码
package org.island.controller;
import org.island.Utils.VerifyCode;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
@WebServlet(name = "ServletYan", value = "/yan")
public class ServletYan extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int width = 200;
int height = 69;
BufferedImage verifyImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
String randomText = VerifyCode.drawRandomText(width, height, verifyImg);
request.getSession().setAttribute("verifyCode", randomText);
response.setContentType("image/png");
OutputStream os = response.getOutputStream();
ImageIO.write(verifyImg, "png", os);
os.flush();
os.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
更新干员信息
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.GanYuan;
import org.island.dao.IGanYuanDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
@RequestMapping("/update")
public class UpdateController {
@RequestMapping("/update_gan")
public void checkName(GanYuan g,HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IGanYuanDao ganyuan = sqlSession.getMapper(IGanYuanDao.class);
System.out.println(g);
ganyuan.update(g);
sqlSession.commit();
sqlSession.close();
try {
response.getWriter().write("update_success");
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/jump")
public void main(HttpServletRequest request, HttpServletResponse response){
try {
System.out.println("测试代码");
request.getRequestDispatcher("WEB-INF/main/error.jsp").forward(request, response);
System.out.println("测试代码");
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
干员登陆
package org.island.controller;
import org.apache.ibatis.session.SqlSession;
import org.island.Utils.Lian;
import org.island.bean.Doctor;
import org.island.bean.User;
import org.island.dao.IDoctorDao;
import org.island.dao.IUserDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/user_login")
public class UserLoginController {
@RequestMapping("/checkName")
public void checkName(String username, String password, HttpServletRequest request, HttpServletResponse response){
SqlSession sqlSession = Lian.getDao();
IUserDao userDao = sqlSession.getMapper(IUserDao.class);
List<User> list = userDao.findAll();
HttpSession session = request.getSession();
session.setAttribute("user_name",username);
System.out.println(username);
System.out.println(password);
boolean flag=false;
String paw ="";
for (User user : list) {
if (username.equals(user.getUsername())){
flag=true;
paw=user.getPassword();
}
}
if (flag) {
if(paw.equals(password)){
try {
response.getWriter().write("ok");
} catch (IOException e) {
e.printStackTrace();
}
}else {
try {
response.getWriter().write("error");
} catch (IOException e) {
e.printStackTrace();
}
}
}else {
try {
response.getWriter().write("no");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}