feat: auto init device
This commit is contained in:
parent
79d16918be
commit
f3445238b3
@ -16,13 +16,8 @@ import java.util.ArrayList;
|
||||
public class DeviceDaoImpl implements DeviceDao {
|
||||
private static final DeviceMapper mapper = ConnectionFactory.getMapper(DeviceMapper.class);
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<Device> findAllDevice() {
|
||||
|
||||
|
||||
return (ArrayList<Device>) mapper.selectAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package cn.edu.cqwu.repair.listener;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.DeviceDao;
|
||||
import cn.edu.cqwu.repair.util.AppInit;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
*/
|
||||
@WebListener
|
||||
public class MyServletContextListener extends AppInit implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ServletContext application = sce.getServletContext();
|
||||
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
|
||||
if (context != null) {
|
||||
DeviceDao deviceDao = context.getBean(DeviceDao.class);
|
||||
initDevice(application, deviceDao);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
|
||||
}
|
||||
}
|
14
src/main/java/cn/edu/cqwu/repair/util/AppInit.java
Normal file
14
src/main/java/cn/edu/cqwu/repair/util/AppInit.java
Normal file
@ -0,0 +1,14 @@
|
||||
package cn.edu.cqwu.repair.util;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.DeviceDao;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
*/
|
||||
public class AppInit {
|
||||
public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) {
|
||||
servletContext.setAttribute("device", deviceDao.findAllDevice());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user