return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<String>(json,HttpStatus.OK);
@Component
public class ScheduledTasks {
@Scheduled(fixedRate = 500)
public void reportCurrentTime() {
System.out.println("Testing successful ");
}
}
ensure you have imported following three packages:
com.fasterxml.jackson.core:jackson-core:2.2.2
com.fasterxml.jackson.core:jackson-databind:2.2.2
com.fasterxml.jackson.core:jackson-annotations:2.2.2
add @EnableWebMvc
@Controller
@EnableWebMvc
@RequestMapping(value = "/articles/action", headers="Accept=*/*", produces="application/json")
public class ArticlesController {
}
src/main/resources/
@RequestMapping(value = "state/{abbreviation}", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody State fetchStateJson(@PathVariable String abbreviation) {
//...
}
@RequestMapping(value = "/reg", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String register(@RequestParam Map<String, String> params){
// ...
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="rollingAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C:/downloads/logs/heuristic.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/heuristic-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder><!-- 必须指定,否则不会往文件输出内容 -->
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
</pattern>
</encoder>
<append>false</append>
<prudent>false</prudent>
</appender>
<root level="INFO">
<appender-ref ref="rollingAppender" />
</root>
</configuration>
return new ModelAndView(new MappingJackson2JsonView(), map);
@RequestMapping with Multiple URI: We can use a single method for handling multiple URIs, for example:
@RequestMapping(value={"/method1","/method1/second"})
@ResponseBody
public String method1(){
return "method1";
}