配置文件



<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>

<dependency>
<groupId>servlet.api</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>

<dependency>
<groupId>json.lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
</dependency>

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>

<dependency>
<groupId>ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>


<?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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--指明 controller 所在包,并扫描其中的注解-->
<context:component-scan base-package="controller"></context:component-scan>

<!-- 开启注解 -->
<mvc:annotation-driven/>


<context:annotation-config/>

<!-- 采用<mvc:default-servlet-handler />

在springMVC-servlet.xml中配置<mvc:default-servlet-handler />后,会在Spring MVC上下文中定义一个org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler,它会像一个检查员,对进入DispatcherServlet的URL进行筛查,如果发现是静态资源的请求,就将该请求转由Web应用服务器默认的Servlet处理,如果不是静态资源的请求,才由DispatcherServlet继续处理。

一般Web应用服务器默认的Servlet名称是"default",因此DefaultServletHttpRequestHandler可以找到它。如果你所有的Web应用服务器的默认Servlet名称不是"default",则需要通过default-servlet-name属性显示指定:

<mvc:default-servlet-handler default-servlet-name="所使用的Web服务器默认使用的Servlet名称" />-->
<mvc:default-servlet-handler/>


<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>


<bean id="StatDataOfGroupService" class="serviceImpl.StatDataOfGroupServiceImpl" lazy-init="true" scope="prototype"></bean>

<!--<context:property-placeholder location="classpath:db.properties" />-->


</beans>


MainController


package controller;

import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import service.IStatDataOfGroupService;
import utils.BeanUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by dzkan on 2016/3/8.
*/
@Controller
@RequestMapping("/user")
public class MainController {
/*注解方式加载bean*/
@Autowired
IStatDataOfGroupService statDataOfGroupService;

// public IStatDataOfGroupService statDataOfGroupService = null;

/* @RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}*/

@RequestMapping(value = "/admin/users", method = RequestMethod.POST)
public String getUsers(ModelMap modelMap) {
return "admin/users";
}

// get请求,访问添加用户 页面
@RequestMapping(value = "/admin/users/add.do", method = RequestMethod.GET)
public String addUser() {
// 返回 admin/addUser.jsp页面
return "admin/addUser";
}

/* @RequestMapping(value = { "/delDepartment.do" }, method = { RequestMethod.POST})
@ResponseBody
public List<Student> test(List<Student> students) {
List<Student> list = new ArrayList<Student>();

Student stu = new Student();
stu.setStuId(1);
stu.setStuName("张三dd");
stu.setStuSex("d");
list.add(stu);

Student stu2 = new Student();
stu2.setStuId(2);
stu2.setStuName("李四");
stu2.setStuSex("女");
list.add(stu2);

return list; //直接返回list对象
}*/

@RequestMapping(value = { "/delDepartment.do" }, method = { RequestMethod.POST})
@ResponseBody
public ReplyInfo delDepartment(@RequestBody List<Student> students, HttpServletResponse res) {
//@RequestBody JSONObject body, HttpServletResponse res
ReplyInfo replyInfo = new ReplyInfo();
List<Student> list = new ArrayList<Student>();
Student stu = new Student();
stu.setStuId(1);
stu.setStuName("张三1");
stu.setStuSex("man");
list.add(stu);

Student stu2 = new Student();
stu2.setStuId(2);
stu2.setStuName("李四");
stu2.setStuSex("女");
list.add(stu2);
replyInfo.setData(list);
return replyInfo; //直接返回list对象
}

@RequestMapping(value = { "/delDepartment" }, method = { RequestMethod.POST})
@ResponseBody
public ReplyInfo delDepartment(@RequestBody Object obj, HttpServletResponse res) {
//@RequestBody JSONObject body, HttpServletResponse res
ReplyInfo replyInfo = new ReplyInfo();
List<Student> list = new ArrayList<Student>();
Student stu = new Student();
stu.setStuId(1);
stu.setStuName("张三2");
stu.setStuSex("man");
list.add(stu);

Student stu2 = new Student();
stu2.setStuId(2);
stu2.setStuName("李四");
stu2.setStuSex("女");
list.add(stu2);
replyInfo.setData(list);

// statDataOfGroupService = (IStatDataOfGroupService) BeanUtil.getBean("StatDataOfGroupService");
String sId = statDataOfGroupService.getPowerStationById("s01");
return replyInfo; //直接返回list对象
}

@RequestMapping(value = "/add.do", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addUser(@RequestBody JSONObject model) {
Map<String, String> map = new HashMap<String, String>(1);
map.put("success", "true");
return map;
}
}


Student

public class Student {
private int stuId;
private String stuName;
private String stuSex;

public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getStuSex() {
return stuSex;
}
public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}


package service;

/**
* Created by p00100 on 2017/3/30.
*/
public interface IStatDataOfGroupService {
/**
* 查询电站对象
* @param sId 为null 则查询所有电站
*/

public String getPowerStationById(String sId);

}


package serviceImpl;

import org.springframework.stereotype.Service;
import service.IStatDataOfGroupService;

/**
* Created by p00100 on 2017/3/30.
*/
@Service
public class StatDataOfGroupServiceImpl implements IStatDataOfGroupService{
public String getPowerStationById(String sId){
String a = "s0001";
return a;
}
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值